From 6cfa4a4360576d7f4052105625017ef9544ae040 Mon Sep 17 00:00:00 2001 From: Max De Marzi Date: Thu, 27 Mar 2014 02:36:02 -0500 Subject: [PATCH] Refactor Other Node Relationships --- lib/neography/rest.rb | 7 +------ .../rest/other_node_relationships.rb | 19 ++++++------------- 2 files changed, 7 insertions(+), 19 deletions(-) diff --git a/lib/neography/rest.rb b/lib/neography/rest.rb index a83d457..d13f40c 100644 --- a/lib/neography/rest.rb +++ b/lib/neography/rest.rb @@ -48,6 +48,7 @@ class Rest include Relationships include RelationshipProperties include NodeRelationships + include OtherNodeRelationships extend Forwardable attr_reader :connection @@ -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) @@ -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 diff --git a/lib/neography/rest/other_node_relationships.rb b/lib/neography/rest/other_node_relationships.rb index 6c4c465..c23ae5f 100644 --- a/lib/neography/rest/other_node_relationships.rb +++ b/lib/neography/rest/other_node_relationships.rb @@ -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" @@ -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 @@ -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