From 49c253c5a38f31d3a43a2c185aa907acbbd1dd61 Mon Sep 17 00:00:00 2001 From: Pablo Fernandez Date: Tue, 27 Mar 2012 19:04:45 -0300 Subject: [PATCH 1/2] Add a way to query the attributes of a relationship --- lib/neography/relationship.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/neography/relationship.rb b/lib/neography/relationship.rb index 1ebd19c..febcc9b 100644 --- a/lib/neography/relationship.rb +++ b/lib/neography/relationship.rb @@ -55,6 +55,11 @@ def del def exist? !self.start_node.neo_server.get_relationship(self.neo_id).nil? end + + def attributes + attrs = self.methods - OpenStruct.instance_methods - Neography::Relationship.instance_methods + attrs.values_at(*self.each_index.select {|i| i.odd?}) + end def other_node(node) if node == @start_node From 5a83e3a954bab7306b62c00058249419bc23a920 Mon Sep 17 00:00:00 2001 From: Pablo Fernandez Date: Tue, 27 Mar 2012 19:16:03 -0300 Subject: [PATCH 2/2] document and fix wrong variable access --- README.rdoc | 1 + lib/neography/relationship.rb | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/README.rdoc b/README.rdoc index 83254fe..5166504 100644 --- a/README.rdoc +++ b/README.rdoc @@ -270,6 +270,7 @@ The Neo4j ID is available by using node.neo_id . new_rel.start_node # Get the start/from node of a relationship new_rel.end_node # Get the end/to node of a relationship new_rel.other_node(n2) # Get the other node of a relationship + new_rel.attributes # Get the attributes of the relationship as an array existing_rel = Neography::Relationship.load(12) # Get an existing relationship by id existing_rel.del # Delete a relationship diff --git a/lib/neography/relationship.rb b/lib/neography/relationship.rb index febcc9b..24d47b8 100644 --- a/lib/neography/relationship.rb +++ b/lib/neography/relationship.rb @@ -58,7 +58,7 @@ def exist? def attributes attrs = self.methods - OpenStruct.instance_methods - Neography::Relationship.instance_methods - attrs.values_at(*self.each_index.select {|i| i.odd?}) + attrs.values_at(*attrs.each_index.select {|i| i.even?}) end def other_node(node) @@ -70,4 +70,4 @@ def other_node(node) end end -end \ No newline at end of file +end