Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base: master
...
compare: master
Checking mergeability… Don't worry, you can still create the pull request.
  • 5 commits
  • 13 files changed
  • 0 commit comments
  • 1 contributor
View
4 README.rdoc
@@ -17,4 +17,6 @@ Ruby client library to Neo4jRest API
Copyright (c) 2011 Carlo Alberto Degli Atti. See LICENSE.txt for
further details.
-=======
+== todo
+
+ - Failure on uninitialized neo4j connection
View
11 lib/neology/graph_mixin/graph_mixin.rb
@@ -1,11 +0,0 @@
-module Neology
-
- module GraphMixin
-
- def id
- RestUtils.get_id @inner_node
- end
-
- end
-
-end
View
8 lib/neology/index_mixin/class_methods.rb
@@ -31,8 +31,12 @@ def add_node_index(node, property_name, value)
end
def find query
- #p "querying: #{self.name},#{_index_name}, #{query}"
- QueryBuilder.new self.name, _index_name, query
+ if query.is_a? Fixnum
+ self.load query
+ else
+ #p "querying: #{self.name},#{_index_name}, #{query}"
+ QueryBuilder.new self.name, _index_name, query
+ end
end
def _index_name
View
3  lib/neology/node_mixin/class_methods.rb
@@ -23,6 +23,9 @@ def new(*args)
def load graph_node_id
graph_node = $neo_server.get_node(graph_node_id)
+ unless graph_node
+ return nil
+ end
_load graph_node
end
View
14 lib/neology/node_mixin/node_mixin.rb
@@ -23,6 +23,18 @@ def id
RestUtils.get_id @inner_node
end
+ def properties
+ inner_node['data']
+ end
+
+ def properties=(args)
+ inner_node['data'] = args
+ end
+
+ def node_or_rel
+ 'node'
+ end
+
def == (other)
inner_node == other.inner_node if other
end
@@ -33,7 +45,6 @@ def del
end
def self.included(base)
-
base.instance_eval do
class << self
alias_method :old_new, :new
@@ -45,7 +56,6 @@ class << self
base.extend Neology::RelsMixin::ClassMethods
base.extend Neology::HasMixin::ClassMethods
base.extend Neology::IndexMixin::ClassMethods
-
end
end
View
17 lib/neology/property_mixin/property_mixin.rb
@@ -2,26 +2,27 @@
require 'neology/utils/data_type_converter'
module Neology
-
module PropertyMixin
+ # TODO: replace node or rel
def []= key, value
- old_value = self.inner_node["data"][key.to_s]
+ old_value = self.properties[key.to_s]
if (value != old_value)
- inner_node["data"][key.to_s] = value
- $neo_server.set_node_properties(inner_node, self.inner_node["data"])
- self.class.update_node_index(self.inner_node, key.to_s, old_value, value) if self.class.is_indexed?(key)
+ self.properties[key.to_s] = value
+ $neo_server.send :"set_#{node_or_rel}_properties", self.id, self.properties
+ if self.class.is_indexed?(key)
+ self.class.send :"update_#{node_or_rel}_index", self.id, key.to_s, old_value, value
+ end
end
end
def [] key
- self.inner_node["data"] = $neo_server.get_node_properties(self.inner_node)
- value = self.inner_node["data"][key.to_s]
+ self.properties = $neo_server.send :"get_#{node_or_rel}_properties", self.id
+ value = self.properties[key.to_s]
options = self.class.properties_hash[key.to_sym]
value = Neology::DataTypeConverter.convert_to_native value, options[:type] if (options && options[:type])
value
end
end
-
end
View
6 lib/neology/relationship_mixin/class_methods.rb
@@ -1,17 +1,14 @@
module Neology
-
module RelationshipMixin
module ClassMethods
def new relationship_name, source_wrapper, destination_wrapper, *options
-
graph_rel = $neo_server.create_relationship(relationship_name, source_wrapper.inner_node, destination_wrapper.inner_node, { "_classname" => self.name })
wrapper = self.old_new graph_rel, source_wrapper, destination_wrapper
wrapper.init_on_create(relationship_name, source_wrapper, destination_wrapper, *options) if wrapper.respond_to? (:init_on_create)
wrapper
-
end
def load graph_rel_id
@@ -20,7 +17,6 @@ def load graph_rel_id
end
def _load graph_rel
-
if graph_rel["data"]["_classname"]
wrapper_class = Neology.const_get(graph_rel["data"]["_classname"].split('::').last)
else
@@ -37,7 +33,5 @@ def is_indexed? property_name
end
end
-
end
-
end
View
22 lib/neology/relationship_mixin/relationship_mixin.rb
@@ -1,26 +1,32 @@
require 'neology/relationship_index_mixin/relationship_index_mixin'
-require 'neology/relationship_property_mixin/relationship_property_mixin'
+require 'neology/property_mixin/property_mixin'
require 'neology/relationship_mixin/class_methods'
module Neology
-
module RelationshipMixin
-
- include Neology::RelationshipPropertyMixin
+ include Neology::PropertyMixin
attr_reader :start_node
attr_reader :end_node
def initialize inner_relationship, start_node, end_node
@inner_relationship = inner_relationship
- @start_node = start_node
- @end_node = end_node
+ @start_node = start_node
+ @end_node = end_node
end
def inner_relationship
@inner_relationship
end
+ def properties
+ inner_relationship['data']
+ end
+
+ def node_or_rel
+ 'relationship'
+ end
+
def id
RestUtils.get_id @inner_relationship
end
@@ -35,7 +41,6 @@ def del
end
def self.included(base)
-
base.instance_eval do
class << self
alias_method :old_new, :new
@@ -44,9 +49,8 @@ class << self
base.extend Neology::RelationshipMixin::ClassMethods
base.extend Neology::RelationshipIndexMixin::ClassMethods
- base.extend Neology::RelationshipPropertyMixin::ClassMethods
+ base.extend Neology::PropertyMixin::ClassMethods
end
end
-
end
View
40 lib/neology/relationship_property_mixin/class_methods.rb
@@ -1,40 +0,0 @@
-module Neology
-
- module RelationshipPropertyMixin
-
- module ClassMethods
-
- def _class_name
- self.name
- end
-
- def relationship_properties_hash
- @relationship_properties_hash ||= { }
- end
-
- def property property_name, options= nil
- #p "defining relationship property #{property_name} with options #{options}"
- self.relationship_properties_hash[property_name] = options if options
- define_relationship_property_setter property_name.to_s
- define_relationship_property_getter property_name.to_s
- end
-
- def define_relationship_property_setter property_name
- #p "defining relationship property setter for property #{property_name}"
- send :define_method, "#{property_name}=".to_sym do |value|
- self[property_name.to_sym]= value
- end
- end
-
- def define_relationship_property_getter property_name
- #p "defining relationship property getter for property #{property_name}"
- send :define_method, property_name.to_sym do
- self[property_name.to_sym]
- end
- end
-
- end
-
- end
-
-end
View
26 lib/neology/relationship_property_mixin/relationship_property_mixin.rb
@@ -1,26 +0,0 @@
-require 'neology/relationship_property_mixin/class_methods'
-
-module Neology
-
- module RelationshipPropertyMixin
-
- def []= key, value
- old_value = self.inner_relationship["data"][key.to_s]
- if (value != old_value)
- self.inner_relationship["data"][key.to_s] = value
- $neo_server.set_relationship_properties(inner_relationship, self.inner_relationship["data"])
- self.class.update_relationship_index(self.inner_relationship, key.to_s, old_value, value) if self.class.is_indexed?(key)
- end
- end
-
- def [] key
- self.inner_relationship["data"] = $neo_server.get_relationship_properties(self.inner_relationship)
- value = self.inner_relationship["data"][key.to_s]
- options = self.class.relationship_properties_hash[key.to_sym]
- value = Neology::DataTypeConverter.convert_to_native value, options[:type] if (options && options[:type])
- value
- end
-
- end
-
-end
View
3  lib/neology/rels_mixin/rels_mixin.rb
@@ -3,11 +3,9 @@
require 'neology/rels_mixin/n_wrapper'
module Neology
-
module RelsMixin
def relationship rel_name
-
rel_decl = self.class.get_rel_decl rel_name
value = $neo_server.get_node_relationships(self.inner_node, "all", rel_name)
@@ -44,5 +42,4 @@ def outgoing rel_name
end
end
-
end
View
44 lib/neology/utils/rest_utils.rb
@@ -1,15 +1,11 @@
module Neology
-
module RestUtils
def self.get_id node
-
node["self"].split('/').last.to_i
-
end
def self.clear_db start_node
-
$neo_server.traverse(start_node, "nodes", { "order" => "depth first",
"uniqueness" => "node global",
"relationships" => [{ "type" => "base", # A hash containg a description of the traversal
@@ -22,15 +18,10 @@ def self.clear_db start_node
end
node_rels = $neo_server.get_node_relationships(start_node)
-
if node_rels
-
node_rels.each do |rel|
-
$neo_server.delete_relationship rel
-
end
-
end
unless start_node.nil? || (start_node && /node\/0/.match(start_node["self"]))
@@ -41,13 +32,9 @@ def self.clear_db start_node
end
def self.find_node property, value, start_node_id = 0, max_depth= 1
-
start_node = $neo_server.get_node start_node_id
-
if start_node
-
filter = "position.endNode().hasProperty('#{property}') && position.endNode().getProperty('#{property}') == '#{value}';"
-
traverser = $neo_server.traverse(start_node, "nodes", {
"order" => "breadth first",
"uniqueness" => "node_global",
@@ -55,19 +42,13 @@ def self.find_node property, value, start_node_id = 0, max_depth= 1
"return filter" => { "language" => "javascript",
"body" => filter }
})
-
return traverser.first unless traverser.empty?
-
end
-
end
-
end
def self.exists_relationship_between? first_node, type, second_node
-
second_node_id = OA::Graph::RestUtils.get_id second_node
-
$neo_server.traverse(first_node, "nodes", {
"order" => "depth first",
"uniqueness" => "node_mixin global",
@@ -77,57 +58,32 @@ def self.exists_relationship_between? first_node, type, second_node
"body" => "position.endNode().getId() == #{second_node_id};" },
"depth" => 1
}).size > 0
-
end
def self.follow_and_return_node node, relationship
-
out_rel = follow_and_return_nodes(node, relationship, limit=1)
-
out_rel.first if out_rel && out_rel.size > 0
-
end
def self.follow_and_return_nodes node, relationship, limit=0
-
out_rel = $neo_server.get_node_relationships(node, "out", relationship)
-
index = 0
-
if out_rel
-
out_rel.find_all do
-
loop = true
-
if limit > 0
-
if index >= limit
-
loop = false
-
end
-
index += 1
-
end
-
loop
-
end.collect do |rel|
-
$neo_server.get_node rel["end"]
-
end
-
else
-
[]
-
end
-
end
-
end
-
end
View
34 spec/property_spec.rb
@@ -6,29 +6,18 @@
describe "node properties" do
it "should allow to assign a property through '[prop_name]='" do
-
node = Neology::Node.new
-
node["property"] = 99
-
reloaded = Neology::Node.load node.id
-
reloaded.inner_node["data"]["property"].should == 99
-
node.del
-
end
it "should allow to read a property through '[prop_name]'" do
-
node = Neology::Node.new
-
node["property"] = 99
-
reloaded = Neology::Node.load node.id
-
reloaded["property"].should == 99
-
node.del
end
@@ -36,47 +25,33 @@
end
describe "relation properties" do
-
it "should allow to assign a property through '[prop_name]='" do
-
node = Neology::Node.new
node_2 = Neology::Node.new
-
rel = Neology::Relationship.new :test, node, node_2
-
rel["property"] = 99
-
reloaded = Neology::Relationship.load rel.id
-
reloaded.inner_relationship["data"]["property"].should == 99
-
rel.del
node.del
node_2.del
-
end
it "should allow to read a property through '[prop_name]'" do
-
node = Neology::Node.new
node_2 = Neology::Node.new
rel = Neology::Relationship.new :test, node, node_2
-
rel["property"] = 99
-
reloaded = Neology::Relationship.load rel.id
-
reloaded["property"].should == 99
rel.del
node.del
node_2.del
-
end
it "should the node properties be converted to native values" do
-
user = NeologyUserAllProperties.new
user[:float_type] = Math::PI
@@ -84,19 +59,14 @@
user[:string_type] = Math::PI
reloaded = Neology::Node.load user.id
-
reloaded[:float_type].should == Math::PI.to_f
-
reloaded[:integer_type].should == Math::PI.to_i
-
reloaded[:string_type].should == Math::PI.to_s
-
user.del
end
it "should the relationship properties be converted to native values" do
-
user = Neology::Node.new
user_2 = Neology::Node.new
rel = NeologyRelationshipAllProperties.new :test, user, user_2
@@ -106,17 +76,13 @@
rel[:string_type] = Math::PI
reloaded = Neology::Relationship.load rel.id
-
reloaded[:float_type].should == Math::PI.to_f
-
reloaded[:integer_type].should == Math::PI.to_i
-
reloaded[:string_type].should == Math::PI.to_s
user.del
user_2.del
rel.del
-
end

No commit comments for this range

Something went wrong with that request. Please try again.