Skip to content

Commit

Permalink
refactoring schema indexes
Browse files Browse the repository at this point in the history
  • Loading branch information
maxdemarzi committed Mar 27, 2014
1 parent ba51a36 commit d206a11
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 39 deletions.
16 changes: 2 additions & 14 deletions lib/neography/rest.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class Rest
include Helpers
include RelationshipTypes
include NodeLabels
include SchemaIndexes
extend Forwardable

attr_reader :connection
Expand All @@ -56,7 +57,6 @@ def initialize(options = ENV['NEO4J_URL'] || {})
@other_node_relationships ||= OtherNodeRelationships.new(@connection)
@node_indexes ||= NodeIndexes.new(@connection)
@node_auto_indexes ||= NodeAutoIndexes.new(@connection)
@schema_indexes ||= SchemaIndexes.new(@connection)
@node_traversal ||= NodeTraversal.new(@connection)
@node_paths ||= NodePaths.new(@connection)

Expand All @@ -75,19 +75,7 @@ def initialize(options = ENV['NEO4J_URL'] || {})
@constraints ||= Constraints.new(@connection)
end

# schema indexes

def get_schema_index(label)
@schema_indexes.list(label)
end

def create_schema_index(label, properties)
@schema_indexes.create(label, properties)
end

def delete_schema_index(label, property)
@schema_indexes.drop(label, property)
end


# constraints

Expand Down
1 change: 0 additions & 1 deletion lib/neography/rest/node_labels.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
module Neography
class Rest
module NodeLabels
extend Neography::Rest::Paths
include Neography::Rest::Helpers

def list_labels
Expand Down
24 changes: 8 additions & 16 deletions lib/neography/rest/schema_indexes.rb
Original file line number Diff line number Diff line change
@@ -1,33 +1,25 @@
module Neography
class Rest
class SchemaIndexes
extend Neography::Rest::Paths
module SchemaIndexes
include Neography::Rest::Helpers

add_path :base, "/schema/index/:label"
add_path :drop, "/schema/index/:label/:index"

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

def list(label)
@connection.get(base_path(:label => label))

def get_schema_index(label)
@connection.get("/schema/index/%{label}" % {:label => label})
end

def drop(label, index)
@connection.delete(drop_path(:label => label, :index => index))
def delete_schema_index(label, index)
@connection.delete("/schema/index/%{label}/%{index}" % {:label => label, :index => index})
end

def create(label, keys = [])
def create_schema_index(label, keys = [])
options = {
:body => (
{ :property_keys => keys
}
).to_json,
:headers => json_content_type
}
@connection.post(base_path(:label => label), options)
@connection.post("/schema/index/%{label}" % {:label => label}, options)
end
end
end
Expand Down
15 changes: 7 additions & 8 deletions spec/unit/rest/schema_index_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,25 @@ module Neography
class Rest
describe SchemaIndexes do

let(:connection) { double(:configuration => "http://configuration") }
subject { SchemaIndexes.new(connection) }
subject { Neography::Rest.new }

it "create schema indexes" do
options = {
:body => '{"property_keys":["name"]}',
:headers => json_content_type
}
connection.should_receive(:post).with("/schema/index/person", options)
subject.create("person", ["name"])
subject.connection.should_receive(:post).with("/schema/index/person", options)
subject.create_schema_index("person", ["name"])
end

it "get schema indexes" do
connection.should_receive(:get).with("/schema/index/person")
subject.list("person")
subject.connection.should_receive(:get).with("/schema/index/person")
subject.get_schema_index("person")
end

it "delete schema indexes" do
connection.should_receive(:delete).with("/schema/index/person/name")
subject.drop("person","name")
subject.connection.should_receive(:delete).with("/schema/index/person/name")
subject.delete_schema_index("person","name")
end

end
Expand Down

0 comments on commit d206a11

Please sign in to comment.