Class: Yaoc::ObjectMapper
- Inherits:
-
Object
- Object
- Yaoc::ObjectMapper
- Defined in:
- lib/yaoc/object_mapper.rb
Instance Attribute Summary collapse
-
#backward_commads ⇒ Object
Returns the value of attribute backward_commads.
-
#dump_result_source ⇒ Object
Returns the value of attribute dump_result_source.
-
#forward_commands ⇒ Object
Returns the value of attribute forward_commands.
-
#load_result_source ⇒ Object
Returns the value of attribute load_result_source.
Instance Method Summary collapse
- #add_mapping(&block) ⇒ Object
- #dump(object) ⇒ Object
-
#initialize(load_result_source, dump_result_source = ->(attrs){ attrs}) ⇒ ObjectMapper
constructor
A new instance of ObjectMapper.
- #load(fetch_able) ⇒ Object
Constructor Details
#initialize(load_result_source, dump_result_source = ->(attrs){ attrs}) ⇒ ObjectMapper
Returns a new instance of ObjectMapper.
7 8 9 10 11 12 13 |
# File 'lib/yaoc/object_mapper.rb', line 7 def initialize(load_result_source, dump_result_source=->(attrs){ attrs}) self.load_result_source = load_result_source.respond_to?(:call) ? load_result_source : ->(attrs){load_result_source.new(attrs)} self.dump_result_source = dump_result_source.respond_to?(:call) ? dump_result_source : ->(attrs){dump_result_source.new(attrs)} self.forward_commands = [] self.backward_commads = [] end |
Instance Attribute Details
#backward_commads ⇒ Object
Returns the value of attribute backward_commads.
4 5 6 |
# File 'lib/yaoc/object_mapper.rb', line 4 def backward_commads @backward_commads end |
#dump_result_source ⇒ Object
Returns the value of attribute dump_result_source.
4 5 6 |
# File 'lib/yaoc/object_mapper.rb', line 4 def dump_result_source @dump_result_source end |
#forward_commands ⇒ Object
Returns the value of attribute forward_commands.
4 5 6 |
# File 'lib/yaoc/object_mapper.rb', line 4 def forward_commands @forward_commands end |
#load_result_source ⇒ Object
Returns the value of attribute load_result_source.
4 5 6 |
# File 'lib/yaoc/object_mapper.rb', line 4 def load_result_source @load_result_source end |
Instance Method Details
#add_mapping(&block) ⇒ Object
23 24 25 26 |
# File 'lib/yaoc/object_mapper.rb', line 23 def add_mapping(&block) instance_eval &block apply_commands end |
#dump(object) ⇒ Object
19 20 21 |
# File 'lib/yaoc/object_mapper.rb', line 19 def dump(object) dump_result_source.call(reverse_converter(object).call()) end |
#load(fetch_able) ⇒ Object
15 16 17 |
# File 'lib/yaoc/object_mapper.rb', line 15 def load(fetch_able) load_result_source.call(converter(fetch_able).call()) end |