Class: ReeMapper::MapperStrategy
- Inherits:
-
Object
- Object
- ReeMapper::MapperStrategy
- Defined in:
- lib/ree_lib/packages/ree_mapper/package/ree_mapper/mapper_strategy.rb
Instance Attribute Summary collapse
-
#always_optional ⇒ Object
readonly
Returns the value of attribute always_optional.
-
#method ⇒ Object
readonly
Returns the value of attribute method.
Instance Method Summary collapse
- #assign_value(object, field, value) ⇒ Object
- #build_object ⇒ Object
- #dto ⇒ Object
- #dto=(dto) ⇒ Object
- #get_value(obj, field) ⇒ Object
- #has_value?(obj, field) ⇒ Boolean
-
#initialize(method:, dto:, always_optional:) ⇒ MapperStrategy
constructor
A new instance of MapperStrategy.
- #initialize_dup(_orig) ⇒ Object
- #prepare_dto(field_names) ⇒ Object
Constructor Details
#initialize(method:, dto:, always_optional:) ⇒ MapperStrategy
Returns a new instance of MapperStrategy.
7 8 9 10 11 |
# File 'lib/ree_lib/packages/ree_mapper/package/ree_mapper/mapper_strategy.rb', line 7 def initialize(method:, dto:, always_optional:) @method = method @output = build_output(dto) @always_optional = always_optional end |
Instance Attribute Details
#always_optional ⇒ Object (readonly)
Returns the value of attribute always_optional.
4 5 6 |
# File 'lib/ree_lib/packages/ree_mapper/package/ree_mapper/mapper_strategy.rb', line 4 def always_optional @always_optional end |
#method ⇒ Object (readonly)
Returns the value of attribute method.
4 5 6 |
# File 'lib/ree_lib/packages/ree_mapper/package/ree_mapper/mapper_strategy.rb', line 4 def method @method end |
Instance Method Details
#assign_value(object, field, value) ⇒ Object
24 25 26 |
# File 'lib/ree_lib/packages/ree_mapper/package/ree_mapper/mapper_strategy.rb', line 24 def assign_value(object, field, value) output.assign_value(object, field, value) end |
#build_object ⇒ Object
19 20 21 |
# File 'lib/ree_lib/packages/ree_mapper/package/ree_mapper/mapper_strategy.rb', line 19 def build_object output.build_object end |
#dto ⇒ Object
53 54 55 |
# File 'lib/ree_lib/packages/ree_mapper/package/ree_mapper/mapper_strategy.rb', line 53 def dto output.dto end |
#dto=(dto) ⇒ Object
47 48 49 50 |
# File 'lib/ree_lib/packages/ree_mapper/package/ree_mapper/mapper_strategy.rb', line 47 def dto=(dto) @output = build_output(dto) nil end |
#get_value(obj, field) ⇒ Object
38 39 40 41 42 43 44 |
# File 'lib/ree_lib/packages/ree_mapper/package/ree_mapper/mapper_strategy.rb', line 38 def get_value(obj, field) if obj.is_a?(Hash) obj.key?(field.from) ? obj[field.from] : obj[field.from_as_str] else obj.public_send(field.from) end end |
#has_value?(obj, field) ⇒ Boolean
29 30 31 32 33 34 35 |
# File 'lib/ree_lib/packages/ree_mapper/package/ree_mapper/mapper_strategy.rb', line 29 def has_value?(obj, field) if obj.is_a?(Hash) obj.key?(field.from) || obj.key?(field.from_as_str) else obj.respond_to?(field.from) end end |
#initialize_dup(_orig) ⇒ Object
13 14 15 16 |
# File 'lib/ree_lib/packages/ree_mapper/package/ree_mapper/mapper_strategy.rb', line 13 def initialize_dup(_orig) @output = @output.dup super end |
#prepare_dto(field_names) ⇒ Object
58 59 60 |
# File 'lib/ree_lib/packages/ree_mapper/package/ree_mapper/mapper_strategy.rb', line 58 def prepare_dto(field_names) output.prepare_dto(field_names) end |