Class: TwoWayMapper::Rule

Inherits:
Object
  • Object
show all
Defined in:
lib/two_way_mapper/rule.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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
  @options = opt
end

Instance Attribute Details

#left_nodesObject (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_nodesObject (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

Returns:

  • (Boolean)


33
34
35
# File 'lib/two_way_mapper/rule.rb', line 33

def from_left_to_right_only?
  @options[: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

Returns:

  • (Boolean)


29
30
31
# File 'lib/two_way_mapper/rule.rb', line 29

def from_right_to_left_only?
  @options[:from_right_to_left_only]
end