-
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
8e66583
commit 7b90ece
Showing
11 changed files
with
210 additions
and
4 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
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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
module Neography | ||
class Config | ||
class << self; attr_accessor :protocol, :server, :port, :log_file, :log_enabled, :logger, :max_threads end | ||
|
||
@protocol = 'http://' | ||
@server = 'localhost' | ||
@port = 7474 | ||
@log_file = 'neography.log' | ||
@log_enabled = false | ||
@logger = Logger.new(@log_file) if @log_enabled | ||
@max_threads = 20 | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
module Neography | ||
class Node < PropertyContainer | ||
|
||
class << self | ||
def create(*args) | ||
# the arguments can be an hash of properties to set or a rest instance | ||
props = (args[0].respond_to?(:each_pair) && args[0]) || args[1] | ||
db = (args[0].is_a?(Neography::Rest) && args[0]) || args[1] || Neography::Rest.new | ||
Neography::Node.new(db.create_node(props)) | ||
end | ||
|
||
def load(*args) | ||
# the first argument can be an hash of properties to set | ||
node = !args[0].is_a?(Neography::Rest) && args[0] || args[1] | ||
|
||
# a db instance can be given, it is the first argument or the second | ||
db = (args[0].is_a?(Neography::Rest) && args[0]) || args[1] || Neography::Rest.new | ||
node = db.get_node(node) | ||
node = Neography::Node.new(node) unless node.nil? | ||
node | ||
end | ||
|
||
#alias_method :new, :create | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
module Neography | ||
class PropertyContainer < OpenStruct | ||
attr_reader :neo_id | ||
|
||
def initialize(hash=nil) | ||
@table = {} | ||
if hash | ||
@neo_id = hash["self"].split('/').last | ||
for k,v in hash["data"] | ||
@table[k.to_sym] = v | ||
new_ostruct_member(k) | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
module Neography | ||
class Relationship < PropertyContainer | ||
attr_reader :start, :end, :type | ||
|
||
def initialize(hash=nil) | ||
super(hash) | ||
@start = hash["start"].split('/').last | ||
@end = hash["end"].split('/').last | ||
@type = hash["type"] | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
require File.join(File.dirname(__FILE__), '..', 'spec_helper') | ||
|
||
describe Neography do | ||
describe "ref_node" do | ||
it "can get the reference node" do | ||
root_node = Neography.ref_node | ||
root_node.should have_key("reference_node") | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
require File.join(File.dirname(__FILE__), '..', 'spec_helper') | ||
|
||
describe Neography::Node do | ||
|
||
describe "create and new" do | ||
it "can create an empty node" do | ||
new_node = Neography::Node.create | ||
new_node.should_not be_nil | ||
end | ||
|
||
it "can create a node with one property" do | ||
new_node = Neography::Node.create("name" => "Max") | ||
new_node.name.should == "Max" | ||
end | ||
|
||
it "can create a node with more than one property" do | ||
new_node = Neography::Node.create("age" => 31, "name" => "Max") | ||
new_node.name.should == "Max" | ||
new_node.age.should == 31 | ||
end | ||
|
||
it "can create a node with more than one property not on the default rest server" do | ||
@neo = Neography::Rest.new | ||
new_node = Neography::Node.create({"age" => 31, "name" => "Max"}, @neo) | ||
new_node.name.should == "Max" | ||
new_node.age.should == 31 | ||
end | ||
|
||
it "can create a node with more than one property not on the default rest server the other way" do | ||
@neo = Neography::Rest.new | ||
new_node = Neography::Node.create(@neo, {"age" => 31, "name" => "Max"}) | ||
new_node.name.should == "Max" | ||
new_node.age.should == 31 | ||
end | ||
end | ||
|
||
|
||
describe "get_node" do | ||
it "can get a node that exists" do | ||
new_node = Neography::Node.create | ||
existing_node = Neography::Node.load(new_node) | ||
existing_node.should_not be_nil | ||
existing_node.neo_id.should_not be_nil | ||
existing_node.neo_id.should == new_node.neo_id | ||
end | ||
|
||
it "returns nil if it tries to get a node that does not exist" do | ||
new_node = Neography::Node.create | ||
fake_node = new_node.neo_id.to_i + 1000 | ||
existing_node = Neography::Node.load(fake_node) | ||
existing_node.should be_nil | ||
end | ||
|
||
it "can get a node that exists not on the default rest server" do | ||
@neo = Neography::Rest.new | ||
new_node = Neography::Node.create(@neo) | ||
existing_node = Neography::Node.load(new_node, @neo) | ||
existing_node.should_not be_nil | ||
existing_node.neo_id.should_not be_nil | ||
existing_node.neo_id.should == new_node.neo_id | ||
end | ||
|
||
it "can get a node that exists not on the default rest server the other way" do | ||
@neo = Neography::Rest.new | ||
new_node = Neography::Node.create(@neo) | ||
existing_node = Neography::Node.load(@neo, new_node) | ||
existing_node.should_not be_nil | ||
existing_node.neo_id.should_not be_nil | ||
existing_node.neo_id.should == new_node.neo_id | ||
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