Module: Neography::Index::ClassMethods

Defined in:
lib/neography/index.rb

Instance Method Summary collapse

Instance Method Details

#find(*args) ⇒ Object


25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/neography/index.rb', line 25

def find(*args)
  db = args[3] ? args.pop : Neography::Rest.new

  if self <= Neography::Node
    nodes = []
    results = db.find_node_index(*args)
    return nil unless results
    results.each do |r|
      node = self.new(r)
      node.neo_server = db
      nodes << node
    end
    nodes.size > 1 ? nodes : nodes.first
  else
    rels = []
    results = db.find_relationship_index(*args)
    return nil unless results
    results.each do |r|
      rel = self.load(r, db)
      rels << rel
    end
    rels.size > 1 ? rels : rels.first
  end  
end