From d206a11000090e5a5e83c9f4b4a5b09a540750ac Mon Sep 17 00:00:00 2001 From: Max De Marzi Date: Thu, 27 Mar 2014 00:09:49 -0500 Subject: [PATCH] refactoring schema indexes --- lib/neography/rest.rb | 16 ++-------------- lib/neography/rest/node_labels.rb | 1 - lib/neography/rest/schema_indexes.rb | 24 ++++++++---------------- spec/unit/rest/schema_index_spec.rb | 15 +++++++-------- 4 files changed, 17 insertions(+), 39 deletions(-) diff --git a/lib/neography/rest.rb b/lib/neography/rest.rb index 46465cd..50a518d 100644 --- a/lib/neography/rest.rb +++ b/lib/neography/rest.rb @@ -41,6 +41,7 @@ class Rest include Helpers include RelationshipTypes include NodeLabels + include SchemaIndexes extend Forwardable attr_reader :connection @@ -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) @@ -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 diff --git a/lib/neography/rest/node_labels.rb b/lib/neography/rest/node_labels.rb index 64bfe61..813330c 100644 --- a/lib/neography/rest/node_labels.rb +++ b/lib/neography/rest/node_labels.rb @@ -1,7 +1,6 @@ module Neography class Rest module NodeLabels - extend Neography::Rest::Paths include Neography::Rest::Helpers def list_labels diff --git a/lib/neography/rest/schema_indexes.rb b/lib/neography/rest/schema_indexes.rb index c538645..00d2df9 100644 --- a/lib/neography/rest/schema_indexes.rb +++ b/lib/neography/rest/schema_indexes.rb @@ -1,25 +1,17 @@ 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 @@ -27,7 +19,7 @@ def create(label, 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 diff --git a/spec/unit/rest/schema_index_spec.rb b/spec/unit/rest/schema_index_spec.rb index 70522ff..7ada28b 100644 --- a/spec/unit/rest/schema_index_spec.rb +++ b/spec/unit/rest/schema_index_spec.rb @@ -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