Class: TwoWayMapper::Node::Base
- Inherits:
-
Object
- Object
- TwoWayMapper::Node::Base
- Defined in:
- lib/two_way_mapper/node/base.rb
Constant Summary collapse
- DIVIDER =
'.'
Instance Attribute Summary collapse
-
#options ⇒ Object
Returns the value of attribute options.
-
#selector ⇒ Object
Returns the value of attribute selector.
Instance Method Summary collapse
-
#initialize(selector, options = {}) ⇒ Base
constructor
A new instance of Base.
- #keys(&block) ⇒ Object
- #read(source) ⇒ Object
- #writable?(current_value, new_value) ⇒ Boolean
- #write(_obj, _value) ⇒ Object
Constructor Details
#initialize(selector, options = {}) ⇒ Base
Returns a new instance of Base.
10 11 12 |
# File 'lib/two_way_mapper/node/base.rb', line 10 def initialize(selector, = {}) @selector, = selector, end |
Instance Attribute Details
#options ⇒ Object
Returns the value of attribute options.
8 9 10 |
# File 'lib/two_way_mapper/node/base.rb', line 8 def end |
#selector ⇒ Object
Returns the value of attribute selector.
8 9 10 |
# File 'lib/two_way_mapper/node/base.rb', line 8 def selector @selector end |
Instance Method Details
#keys(&block) ⇒ Object
14 15 16 17 18 19 20 |
# File 'lib/two_way_mapper/node/base.rb', line 14 def keys(&block) unless block block = [:stringify_keys] ? :to_s : :to_sym block = block.to_proc end selector.split(DIVIDER).map(&block) end |
#read(source) ⇒ Object
22 23 24 |
# File 'lib/two_way_mapper/node/base.rb', line 22 def read(source) rewind_forward(source) { |_obj, _key| return nil } end |
#writable?(current_value, new_value) ⇒ Boolean
30 31 32 33 34 |
# File 'lib/two_way_mapper/node/base.rb', line 30 def writable?(current_value, new_value) ![:write_if] || ![:write_if].respond_to?(:call) || [:write_if].call(current_value, new_value) end |
#write(_obj, _value) ⇒ Object
26 27 28 |
# File 'lib/two_way_mapper/node/base.rb', line 26 def write(_obj, _value) raise NotImplementedError end |