Class: Reorm::FieldPath

Inherits:
Object
  • Object
show all
Defined in:
lib/reorm/field_path.rb

Instance Method Summary collapse

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

Returns:

  • (Boolean)


25
26
27
# File 'lib/reorm/field_path.rb', line 25

def exists?(document)
  locate(document)[1]
end

#nameObject



11
12
13
# File 'lib/reorm/field_path.rb', line 11

def name
  @path.last
end

#to_sObject



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

Raises:



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