Skip to content

Commit

Permalink
Refactor Gremlin
Browse files Browse the repository at this point in the history
  • Loading branch information
maxdemarzi committed Mar 27, 2014
1 parent a82b765 commit 72d12d2
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 19 deletions.
8 changes: 1 addition & 7 deletions lib/neography/rest.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class Rest
include NodeTraversal
include NodePaths
include Cypher
include Gremlin
extend Forwardable

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

@gremlin ||= Gremlin.new(@connection)
@extensions ||= Extensions.new(@connection)
@batch ||= Batch.new(@connection)
@clean ||= Clean.new(@connection)
Expand Down Expand Up @@ -101,12 +101,6 @@ def get_relationship_end_node(rel)
get_node(rel["end"])
end

# gremlin script

def execute_script(script, params = {})
@gremlin.execute(script, params)
end

# unmanaged extensions

def post_extension(path, params = {}, headers = nil)
Expand Down
8 changes: 2 additions & 6 deletions lib/neography/rest/gremlin.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
module Neography
class Rest
class Gremlin
module Gremlin
include Neography::Rest::Helpers

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

def execute(script, parameters = {})
def execute_script(script, parameters = {})
options = {
:body => {
:script => script,
Expand Down
11 changes: 5 additions & 6 deletions spec/unit/rest/gremlin_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,20 @@ module Neography
class Rest
describe Gremlin do

let(:connection) { double(:gremlin_path => "/gremlin") }
subject { Gremlin.new(connection) }
subject { Neography::Rest.new }

it "executes a gremlin script" do
options = {
:body=>"{\"script\":\"SOME SCRIPT\",\"params\":{\"foo\":\"bar\",\"baz\":\"qux\"}}",
:headers=>{"Content-Type"=>"application/json"}
}
connection.should_receive(:post).with("/gremlin", options)
subject.execute("SOME SCRIPT", { :foo => "bar", :baz => "qux" })
subject.connection.should_receive(:post).with("/ext/GremlinPlugin/graphdb/execute_script", options)
subject.execute_script("SOME SCRIPT", { :foo => "bar", :baz => "qux" })
end

it "returns nil if script result is null" do
connection.stub(:post).and_return("null")
subject.execute("", {}).should be_nil
subject.connection.stub(:post).and_return("null")
subject.execute_script("", {}).should be_nil
end

end
Expand Down

0 comments on commit 72d12d2

Please sign in to comment.