Class: Redress::Utils::ParseAttributesFromParams

Inherits:
Object
  • Object
show all
Defined in:
lib/redress/utils/parse_attributes_from_params.rb

Instance Method Summary collapse

Constructor Details

#initialize(klass, params, options = nil) ⇒ ParseAttributesFromParams

Returns a new instance of ParseAttributesFromParams.



8
9
10
11
12
# File 'lib/redress/utils/parse_attributes_from_params.rb', line 8

def initialize(klass, params, options = nil)
  @klass = klass
  @params = convert_params_to_hash(params)
  @options = (options || {})
end

Instance Method Details

#attributesObject Also known as: to_h



14
15
16
# File 'lib/redress/utils/parse_attributes_from_params.rb', line 14

def attributes
  @attributes ||= extract_attributes
end

#full_prefixObject



29
30
31
# File 'lib/redress/utils/parse_attributes_from_params.rb', line 29

def full_prefix
  @full_prefix ||= "#{prefix}_"
end

#model_attributesObject



19
20
21
# File 'lib/redress/utils/parse_attributes_from_params.rb', line 19

def model_attributes
  @params.fetch(@klass.mimicked_model_name, {})
end

#prefixObject



23
24
25
26
27
# File 'lib/redress/utils/parse_attributes_from_params.rb', line 23

def prefix
  return if @options[:prefix].blank?

  @prefix ||= @options[:prefix].to_s
end