Skip to content

Commit

Permalink
Refactor Other Node Relationships
Browse files Browse the repository at this point in the history
  • Loading branch information
maxdemarzi committed Mar 27, 2014
1 parent 901f6ec commit 6cfa4a4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 19 deletions.
7 changes: 1 addition & 6 deletions lib/neography/rest.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class Rest
include Relationships
include RelationshipProperties
include NodeRelationships
include OtherNodeRelationships
extend Forwardable

attr_reader :connection
Expand All @@ -57,7 +58,6 @@ class Rest
def initialize(options = ENV['NEO4J_URL'] || {})
@connection = Connection.new(options)

@other_node_relationships ||= OtherNodeRelationships.new(@connection)
@node_indexes ||= NodeIndexes.new(@connection)
@node_auto_indexes ||= NodeAutoIndexes.new(@connection)
@node_traversal ||= NodeTraversal.new(@connection)
Expand Down Expand Up @@ -100,11 +100,6 @@ def get_relationship_end_node(rel)
get_node(rel["end"])
end

def get_node_relationships_to(id, other_id, dir = "all", types = nil)
@other_node_relationships.get(id, other_id, dir, Array(types || [nil]))
end


# node indexes

def list_node_indexes
Expand Down
19 changes: 6 additions & 13 deletions lib/neography/rest/other_node_relationships.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,9 @@
module Neography
class Rest
class OtherNodeRelationships
extend Neography::Rest::Paths
module OtherNodeRelationships
include Neography::Rest::Helpers

add_path :base, "/node/:id/traverse/relationship"

def initialize(connection)
@connection ||= connection
end

def get(id, other_id, direction = "all", types = [nil])

def get_node_relationships_to(id, other_id, direction = "all", types = [nil] )

body = case parse_direction(direction)
when "all"
Expand All @@ -21,9 +14,9 @@ def get(id, other_id, direction = "all", types = [nil])
"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)})} }
relationships = {:relationships => Array(types).map{|row| Hash[{:type => row}].merge({:direction => parse_direction(direction)})} }

if types.first.nil?
if Array(types).first.nil?
relationships = {}
end

Expand All @@ -37,7 +30,7 @@ def get(id, other_id, direction = "all", types = [nil])
:headers => json_content_type
}

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

end
Expand Down

0 comments on commit 6cfa4a4

Please sign in to comment.