Skip to content

Commit

Permalink
Refactor Relationships
Browse files Browse the repository at this point in the history
  • Loading branch information
maxdemarzi committed Mar 27, 2014
1 parent ad95b7c commit a7fa348
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 31 deletions.
12 changes: 2 additions & 10 deletions lib/neography/rest.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class Rest
include Transactions
include Nodes
include NodeProperties
include Relationships
extend Forwardable

attr_reader :connection
Expand All @@ -62,7 +63,6 @@ def initialize(options = ENV['NEO4J_URL'] || {})
@node_traversal ||= NodeTraversal.new(@connection)
@node_paths ||= NodePaths.new(@connection)

@relationships ||= Relationships.new(@connection)
@relationship_properties ||= RelationshipProperties.new(@connection)
@relationship_indexes ||= RelationshipIndexes.new(@connection)
@relationship_auto_indexes ||= RelationshipAutoIndexes.new(@connection)
Expand Down Expand Up @@ -91,24 +91,16 @@ def delete_node!(id)
# get("/nodes/")
# end


# relationships

def get_relationship(id)
@relationships.get(id)
end

def delete_relationship(id)
@relationships.delete(id)
end

def get_relationship_start_node(rel)
get_node(rel["start"])
end

def get_relationship_end_node(rel)
get_node(rel["end"])
end


# relationship properties

Expand Down
4 changes: 2 additions & 2 deletions lib/neography/rest/batch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,11 @@ def get_node_relationships(id, direction = nil, types = nil)
# Relationships

def get_relationship(id)
get Relationships.base_path(:id => get_id(id))
get "/relationship/%{id}" % {:id => get_id(id)}
end

def delete_relationship(id)
delete Relationships.base_path(:id => get_id(id))
delete "/relationship/%{id}" % {:id => get_id(id)}
end

def create_relationship(type, from, to, data = nil)
Expand Down
19 changes: 6 additions & 13 deletions lib/neography/rest/relationships.rb
Original file line number Diff line number Diff line change
@@ -1,21 +1,14 @@
module Neography
class Rest
class Relationships
extend Neography::Rest::Paths
module Relationships
include Neography::Rest::Helpers

add_path :base, "/relationship/:id"

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

def get(id)
@connection.get(base_path(:id => get_id(id)))

def get_relationship(id)
@connection.get("/relationship/%{id}" % {:id => get_id(id)})
end

def delete(id)
@connection.delete(base_path(:id => get_id(id)))
def delete_relationship(id)
@connection.delete("/relationship/%{id}" % {:id => get_id(id)})
end

end
Expand Down
11 changes: 5 additions & 6 deletions spec/unit/rest/relationships_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,16 @@ module Neography
class Rest
describe Relationships do

let(:connection) { double }
subject { Relationships.new(connection) }
subject { Neography::Rest.new }

it "gets a relationship" do
connection.should_receive(:get).with("/relationship/42")
subject.get("42")
subject.connection.should_receive(:get).with("/relationship/42")
subject.get_relationship("42")
end

it "deletes a relationship" do
connection.should_receive(:delete).with("/relationship/42")
subject.delete("42")
subject.connection.should_receive(:delete).with("/relationship/42")
subject.delete_relationship("42")
end

end
Expand Down

0 comments on commit a7fa348

Please sign in to comment.