-
Notifications
You must be signed in to change notification settings - Fork 135
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
28313e1
commit 65f6ca9
Showing
4 changed files
with
51 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |