Class: TwoWayMapper::Rule
- Inherits:
-
Object
- Object
- TwoWayMapper::Rule
- Defined in:
- lib/two_way_mapper/rule.rb
Instance Attribute Summary collapse
-
#left ⇒ Object
readonly
Returns the value of attribute left.
-
#right ⇒ Object
readonly
Returns the value of attribute right.
Instance Method Summary collapse
- #from_left_to_right(left_obj, right_obj) ⇒ Object
- #from_left_to_right_only? ⇒ Boolean
- #from_right_to_left(left_obj, right_obj) ⇒ Object
- #from_right_to_left_only? ⇒ Boolean
-
#initialize(left, right, opt = {}) ⇒ Rule
constructor
A new instance of Rule.
Constructor Details
#initialize(left, right, opt = {}) ⇒ Rule
Returns a new instance of Rule.
7 8 9 10 11 |
# File 'lib/two_way_mapper/rule.rb', line 7 def initialize(left, right, opt = {}) @left = left @right = right = opt end |
Instance Attribute Details
#left ⇒ Object (readonly)
Returns the value of attribute left.
5 6 7 |
# File 'lib/two_way_mapper/rule.rb', line 5 def left @left end |
#right ⇒ Object (readonly)
Returns the value of attribute right.
5 6 7 |
# File 'lib/two_way_mapper/rule.rb', line 5 def right @right end |
Instance Method Details
#from_left_to_right(left_obj, right_obj) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/two_way_mapper/rule.rb', line 13 def from_left_to_right(left_obj, right_obj) return right_obj if from_right_to_left_only? value = left.read(left_obj) value = map_value(value, true) if [:on_left_to_right].respond_to?(:call) value = [:on_left_to_right].call(value, left_obj, right_obj) end right.write(right_obj, value) right_obj end |
#from_left_to_right_only? ⇒ Boolean
43 44 45 |
# File 'lib/two_way_mapper/rule.rb', line 43 def from_left_to_right_only? [:from_left_to_right_only] end |
#from_right_to_left(left_obj, right_obj) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/two_way_mapper/rule.rb', line 26 def from_right_to_left(left_obj, right_obj) return left_obj if from_left_to_right_only? value = right.read(right_obj) value = map_value(value, false) if [:on_right_to_left].respond_to?(:call) value = [:on_right_to_left].call(value, left_obj, right_obj) end left.write(left_obj, value) left_obj end |
#from_right_to_left_only? ⇒ Boolean
39 40 41 |
# File 'lib/two_way_mapper/rule.rb', line 39 def from_right_to_left_only? [:from_right_to_left_only] end |