diff --git a/lib/neography/index.rb b/lib/neography/index.rb index c9af1ad..6c73532 100644 --- a/lib/neography/index.rb +++ b/lib/neography/index.rb @@ -1,13 +1,43 @@ module Neography module Index - def index(*args) - + def self.included(base) + base.extend(ClassMethods) + end + + def add_to_index(index, key, value) + if self.is_a? Neography::Node + neo_server.add_node_to_index(index, key, value, self.neo_id) + else + neo_server.add_relationship_to_index(index, key, value, self.neo_id) + end end - def find(*args) - + def remove_from_index(*args) + if self.is_a? Neography::Node + neo_server.remove_node_from_index(*args) + else + neo_server.remove_relationship_from_index(*args) + end end + module ClassMethods + def find(*args) + if name == "Neography::Node" + if args.size > 1 + neo_server.find_node_index(*args) + else + neo_server.get_node_index(*args) + end + else + if args.size > 1 + neo_server.find_relationship_index(*args) + else + neo_server.get_relationship_index(*args) + end + end + end + end + end end \ No newline at end of file diff --git a/lib/neography/node.rb b/lib/neography/node.rb index 0f8ecec..8855c23 100644 --- a/lib/neography/node.rb +++ b/lib/neography/node.rb @@ -1,6 +1,6 @@ module Neography class Node < PropertyContainer - extend Neography::Index + include Neography::Index include Neography::NodeRelationship include Neography::NodePath include Neography::Equal diff --git a/lib/neography/relationship.rb b/lib/neography/relationship.rb index 24d47b8..4330ca2 100644 --- a/lib/neography/relationship.rb +++ b/lib/neography/relationship.rb @@ -2,7 +2,7 @@ module Neography class Relationship < PropertyContainer include Neography::Equal include Neography::Property - extend Neography::Index + include Neography::Index attr_accessor :start_node, :end_node, :rel_type diff --git a/spec/integration/index_spec.rb b/spec/integration/index_spec.rb index 14a406b..6fc53b0 100644 --- a/spec/integration/index_spec.rb +++ b/spec/integration/index_spec.rb @@ -1,32 +1,21 @@ require File.join(File.dirname(__FILE__), '..', 'spec_helper') -describe Neography::Relationship, "find" do - before(:each) do - pending "Phase 2 - Index part is not done." - Neography::Relationship.index(:strength) - end +describe Neography::Index do - it "can index when Neography::Relationships are created" do - a = Neography::Node.create - b = Neography::Node.create - r = Neography::Relationship.create(:friends, a, b) - r[:strength] = 'strong' - Neography::Relationship.find('strength: strong').first.should == r + it "can add a node to an index" do + new_node = Neography::Node.create + key = generate_text(6) + value = generate_text + new_node.add_to_index("node_test_index", key, value) end - it "can remove index when Neography::Relationship is deleted, just like nodes" do - a = Neography::Node.create - b = Neography::Node.create - r = Neography::Relationship.create(:friends, a, b) - r[:strength] = 'weak' - r2 = Neography::Relationship.find('strength: weak').first - r2.should == r - r2.del - Neography::Relationship.find('strength: weak').should be_empty + it "can add a relationship to an index" do + node1 = Neography::Node.create + node2 = Neography::Node.create + r = Neography::Relationship.create(:friends, node1, node2) + key = generate_text(6) + value = generate_text + r.add_to_index("relationship_test_index", key, value) end -end - - -describe Neography::Node, "find" do - -end + +end \ No newline at end of file