Class: Reorm::FieldPath
- Inherits:
-
Object
- Object
- Reorm::FieldPath
- Defined in:
- lib/reorm/field_path.rb
Instance Method Summary collapse
- #exists?(document) ⇒ Boolean
-
#initialize(*path) ⇒ FieldPath
constructor
A new instance of FieldPath.
- #name ⇒ Object
- #to_s ⇒ Object
- #value(document) ⇒ Object
- #value!(document) ⇒ Object
Constructor Details
#initialize(*path) ⇒ FieldPath
Returns a new instance of FieldPath.
7 8 9 |
# File 'lib/reorm/field_path.rb', line 7 def initialize(*path) @path = [].concat(path) end |
Instance Method Details
#exists?(document) ⇒ Boolean
25 26 27 |
# File 'lib/reorm/field_path.rb', line 25 def exists?(document) locate(document)[1] end |
#name ⇒ Object
11 12 13 |
# File 'lib/reorm/field_path.rb', line 11 def name @path.last end |
#to_s ⇒ Object
29 30 31 |
# File 'lib/reorm/field_path.rb', line 29 def to_s @path.join(" -> ") end |
#value(document) ⇒ Object
15 16 17 |
# File 'lib/reorm/field_path.rb', line 15 def value(document) locate(document).first end |
#value!(document) ⇒ Object
19 20 21 22 23 |
# File 'lib/reorm/field_path.rb', line 19 def value!(document) result = locate(document) raise Error, "Unable to locate the #{name} (full path: #{self}) field for an instance of the #{document.class.name} class." if !result[1] result[0] end |