Module: Neography::Rest::OtherNodeRelationships

Includes:
Helpers
Included in:
Neography::Rest
Defined in:
lib/neography/rest/other_node_relationships.rb

Instance Method Summary collapse

Methods included from Helpers

#encode, #escape, #get_id, #json_content_type, #parse_depth, #parse_direction, #parse_order, #parse_type, #parse_uniqueness

Instance Method Details

#get_node_relationships_to(id, other_id, direction = "all", types = [nil]) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/neography/rest/other_node_relationships.rb', line 6

def get_node_relationships_to(id, other_id, direction = "all", types = [nil] )
  
  body = case parse_direction(direction)
           when "all"
             "position.endNode().getId() == " + get_id(other_id)
           when "in"
             "position.length() > 0 && position.lastRelationship().getStartNode().getId() == " + get_id(other_id)
           when "out"
             "position.length() > 0 && position.lastRelationship().getEndNode().getId() == " + get_id(other_id) 
          end

  relationships = {:relationships => Array(types).map{|row| Hash[{:type => row}].merge({:direction => parse_direction(direction)})} }

  if Array(types).first.nil?
    relationships = {}
  end
          
  options = {
    :body => {:order      => "breadth_first",
              :uniqueness => "relationship_global",
              :max_depth  => 1,
              :return_filter => {:language => "javascript",
                                 :body =>  body }
              }.merge(relationships).to_json,
    :headers => json_content_type
  }

  @connection.post("/node/%{id}/traverse/relationship" % {:id => get_id(id)}, options) || []
end