diff --git a/lib/neography/rest.rb b/lib/neography/rest.rb index 086b27c..ee4ba60 100644 --- a/lib/neography/rest.rb +++ b/lib/neography/rest.rb @@ -54,6 +54,7 @@ class Rest include NodeTraversal include NodePaths include Cypher + include Gremlin extend Forwardable attr_reader :connection @@ -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) @@ -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) diff --git a/lib/neography/rest/gremlin.rb b/lib/neography/rest/gremlin.rb index 14ee0f3..c3b6842 100644 --- a/lib/neography/rest/gremlin.rb +++ b/lib/neography/rest/gremlin.rb @@ -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, diff --git a/spec/unit/rest/gremlin_spec.rb b/spec/unit/rest/gremlin_spec.rb index 34dad17..46e2fbf 100644 --- a/spec/unit/rest/gremlin_spec.rb +++ b/spec/unit/rest/gremlin_spec.rb @@ -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