Class: TwoWayMapper::Mapping
- Inherits:
-
Object
- Object
- TwoWayMapper::Mapping
- Defined in:
- lib/two_way_mapper/mapping.rb
Constant Summary collapse
- DIRECTIONS =
[:left, :right].freeze
Instance Attribute Summary collapse
-
#left_class ⇒ Object
readonly
Returns the value of attribute left_class.
-
#left_options ⇒ Object
readonly
Returns the value of attribute left_options.
-
#right_class ⇒ Object
readonly
Returns the value of attribute right_class.
-
#right_options ⇒ Object
readonly
Returns the value of attribute right_options.
-
#rules ⇒ Object
readonly
Returns the value of attribute rules.
Instance Method Summary collapse
-
#initialize ⇒ Mapping
constructor
A new instance of Mapping.
- #rule(left_selector, right_selector = {}, options = {}) ⇒ Object
Constructor Details
#initialize ⇒ Mapping
Returns a new instance of Mapping.
9 10 11 |
# File 'lib/two_way_mapper/mapping.rb', line 9 def initialize @rules = [] end |
Instance Attribute Details
#left_class ⇒ Object (readonly)
Returns the value of attribute left_class.
7 8 9 |
# File 'lib/two_way_mapper/mapping.rb', line 7 def left_class @left_class end |
#left_options ⇒ Object (readonly)
Returns the value of attribute left_options.
7 8 9 |
# File 'lib/two_way_mapper/mapping.rb', line 7 def end |
#right_class ⇒ Object (readonly)
Returns the value of attribute right_class.
7 8 9 |
# File 'lib/two_way_mapper/mapping.rb', line 7 def right_class @right_class end |
#right_options ⇒ Object (readonly)
Returns the value of attribute right_options.
7 8 9 |
# File 'lib/two_way_mapper/mapping.rb', line 7 def end |
#rules ⇒ Object (readonly)
Returns the value of attribute rules.
7 8 9 |
# File 'lib/two_way_mapper/mapping.rb', line 7 def rules @rules end |
Instance Method Details
#rule(left_selector, right_selector = {}, options = {}) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/two_way_mapper/mapping.rb', line 35 def rule(left_selector, right_selector = {}, = {}) raise 'You need to set left before calling rule' unless left_class raise 'You need to set right before calling rule' unless right_class opt = .dup left_opt = opt.delete(:left) || {} right_opt = opt.delete(:right) || {} if left_selector.is_a?(Hash) raise ArgumentError if left_selector.count < 2 opt = left_selector left_selector = opt.keys.first left_opt.merge! opt.delete(left_selector) right_selector = opt.keys.first right_opt.merge!(opt.delete(right_selector)) end left = left_class.new(left_selector, .merge(left_opt)) right = right_class.new(right_selector, .merge(right_opt)) @rules << Rule.new(left, right, opt) end |