Skip to content

Commit

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

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

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

# cypher query

def execute_query(query, params = {}, cypher_options = nil)
@cypher.query(query, params, cypher_options)
end

# gremlin script

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

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

def query(query, parameters = {}, cypher_options = nil)
def execute_query(query, parameters = {}, cypher_options = nil)
options = {
:body => {
:query => query,
Expand Down
7 changes: 3 additions & 4 deletions spec/unit/rest/cypher_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,15 @@ module Neography
class Rest
describe Cypher do

let(:connection) { double(:cypher_path => "/cypher") }
subject { Cypher.new(connection) }
subject { Neography::Rest.new }

it "executes a cypher query" do
options = {
:body=>"{\"query\":\"SOME QUERY\",\"params\":{\"foo\":\"bar\",\"baz\":\"qux\"}}",
:headers=>{"Content-Type"=>"application/json", "Accept"=>"application/json;stream=true;charset=UTF-8"}
}
connection.should_receive(:post).with("/cypher", options)
subject.query("SOME QUERY", { :foo => "bar", :baz => "qux" })
subject.connection.should_receive(:post).with("/cypher", options)
subject.execute_query("SOME QUERY", { :foo => "bar", :baz => "qux" })
end

end
Expand Down

0 comments on commit a82b765

Please sign in to comment.