Class: TwoWayMapper::Rule
- Inherits:
-
Object
- Object
- TwoWayMapper::Rule
- Defined in:
- lib/two_way_mapper/rule.rb
Instance Attribute Summary collapse
-
#left_nodes ⇒ Object
readonly
Returns the value of attribute left_nodes.
-
#right_nodes ⇒ Object
readonly
Returns the value of attribute right_nodes.
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_nodes, right_nodes, opt = {}) ⇒ Rule
constructor
A new instance of Rule.
Constructor Details
#initialize(left_nodes, right_nodes, 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_nodes, right_nodes, opt = {}) @left_nodes = left_nodes @right_nodes = right_nodes = opt end |
Instance Attribute Details
#left_nodes ⇒ Object (readonly)
Returns the value of attribute left_nodes.
5 6 7 |
# File 'lib/two_way_mapper/rule.rb', line 5 def left_nodes @left_nodes end |
#right_nodes ⇒ Object (readonly)
Returns the value of attribute right_nodes.
5 6 7 |
# File 'lib/two_way_mapper/rule.rb', line 5 def right_nodes @right_nodes end |
Instance Method Details
#from_left_to_right(left_obj, right_obj) ⇒ Object
13 14 15 16 17 18 19 |
# 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 = read(left_nodes, [left_obj, right_obj], true) write(right_nodes, right_obj, value) end |
#from_left_to_right_only? ⇒ Boolean
33 34 35 |
# File 'lib/two_way_mapper/rule.rb', line 33 def from_left_to_right_only? [:from_left_to_right_only] end |
#from_right_to_left(left_obj, right_obj) ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/two_way_mapper/rule.rb', line 21 def from_right_to_left(left_obj, right_obj) return left_obj if from_left_to_right_only? value = read(right_nodes, [left_obj, right_obj], false) write(left_nodes, left_obj, value) end |
#from_right_to_left_only? ⇒ Boolean
29 30 31 |
# File 'lib/two_way_mapper/rule.rb', line 29 def from_right_to_left_only? [:from_right_to_left_only] end |