Class: Neography::Rest::OtherNodeRelationships

Inherits:
Object
  • Object
show all
Extended by:
Paths
Includes:
Helpers
Defined in:
lib/neography/rest/other_node_relationships.rb

Instance Method Summary collapse

Methods included from Paths

add_path, build_path, encode

Methods included from Helpers

#get_id, #json_content_type, #parse_direction

Constructor Details

#initialize(connection) ⇒ OtherNodeRelationships

Returns a new instance of OtherNodeRelationships.



9
10
11
# File 'lib/neography/rest/other_node_relationships.rb', line 9

def initialize(connection)
  @connection = connection
end

Instance Method Details

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



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/neography/rest/other_node_relationships.rb', line 13

def get(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 => types.map{|row| Hash[{:type => row}].merge({:direction => parse_direction(direction)})} }

  if 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
  }

  node_relationships = @connection.post(base_path(:id => get_id(id)), options) || []

  return nil if node_relationships.empty?
  node_relationships
end