Method: NoSE::KeyPath#initialize

Defined in:
lib/nose/statements.rb

#initialize(keys = []) ⇒ KeyPath

Returns a new instance of KeyPath.



112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/nose/statements.rb', line 112

def initialize(keys = [])
  fail InvalidKeyPathException, 'first key must be an ID' \
    unless keys.empty? || keys.first.instance_of?(Fields::IDField)

  keys_match = keys.each_cons(2).all? do |prev_key, key|
    key.parent == prev_key.entity
  end
  fail InvalidKeyPathException, 'keys must match along the path' \
    unless keys_match

  @keys = keys
end