neo4jr-simple 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.document +5 -0
- data/.gitignore +21 -0
- data/LICENSE +20 -0
- data/README.rdoc +67 -0
- data/Rakefile +45 -0
- data/VERSION +1 -0
- data/lib/jars/jta-1_1.jar +0 -0
- data/lib/jars/neo-1.0-b9.jar +0 -0
- data/lib/jars/shell-1.0-b9.jar +0 -0
- data/lib/neo4jr-simple.rb +18 -0
- data/lib/neo4jr/configuration.rb +13 -0
- data/lib/neo4jr/db.rb +53 -0
- data/lib/neo4jr/direction.rb +7 -0
- data/lib/neo4jr/node_extension.rb +22 -0
- data/lib/neo4jr/order.rb +7 -0
- data/lib/neo4jr/relationship_type.rb +48 -0
- data/lib/neo4jr/returnable_evaluator.rb +30 -0
- data/lib/neo4jr/stop_evaluator.rb +43 -0
- data/lib/neo4jr/traverser_extension.rb +5 -0
- data/lib/neo4jr/version.rb +3 -0
- data/neo4jr-simple.gemspec +99 -0
- data/spec/db_spec.rb +11 -0
- data/spec/functional_example_spec.rb +55 -0
- data/spec/node_extension_spec.rb +18 -0
- data/spec/returnable_evaluator_spec.rb +15 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +15 -0
- data/spec/stop_evaluator_spec.rb +32 -0
- data/spec/test-imdb-database/active_tx_log +1 -0
- data/spec/test-imdb-database/neostore +0 -0
- data/spec/test-imdb-database/neostore.id +0 -0
- data/spec/test-imdb-database/neostore.nodestore.db +0 -0
- data/spec/test-imdb-database/neostore.nodestore.db.id +0 -0
- data/spec/test-imdb-database/neostore.propertystore.db +0 -0
- data/spec/test-imdb-database/neostore.propertystore.db.arrays +0 -0
- data/spec/test-imdb-database/neostore.propertystore.db.arrays.id +0 -0
- data/spec/test-imdb-database/neostore.propertystore.db.id +0 -0
- data/spec/test-imdb-database/neostore.propertystore.db.index +0 -0
- data/spec/test-imdb-database/neostore.propertystore.db.index.id +0 -0
- data/spec/test-imdb-database/neostore.propertystore.db.index.keys +0 -0
- data/spec/test-imdb-database/neostore.propertystore.db.index.keys.id +0 -0
- data/spec/test-imdb-database/neostore.propertystore.db.strings +0 -0
- data/spec/test-imdb-database/neostore.propertystore.db.strings.id +0 -0
- data/spec/test-imdb-database/neostore.relationshipstore.db +0 -0
- data/spec/test-imdb-database/neostore.relationshipstore.db.id +0 -0
- data/spec/test-imdb-database/neostore.relationshiptypestore.db +0 -0
- data/spec/test-imdb-database/neostore.relationshiptypestore.db.id +0 -0
- data/spec/test-imdb-database/neostore.relationshiptypestore.db.names +0 -0
- data/spec/test-imdb-database/neostore.relationshiptypestore.db.names.id +0 -0
- data/spec/test-imdb-database/nioneo_logical.log.active +0 -0
- data/spec/test-imdb-database/tm_tx_log.1 +0 -0
- metadata +120 -0
data/.document
ADDED
data/.gitignore
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Matthew Deiters
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
= neo4jr-simple
|
2
|
+
|
3
|
+
A simple, ready to go JRuby wrapper for the Neo4j graph database engine which provides:
|
4
|
+
* The Neo4j Core Java Library (required and ready to use)
|
5
|
+
* Raw access to the Java API (using Neo4j::DB.instance )
|
6
|
+
* Extensions to the Java API to make node manipulation and traversal more rubyesque
|
7
|
+
* Working specs
|
8
|
+
* Loaded Neo4j sample database with IMDB data
|
9
|
+
* Nothing more then Neo4j goodness
|
10
|
+
|
11
|
+
== Prerequisites
|
12
|
+
|
13
|
+
* Java
|
14
|
+
* JRuby
|
15
|
+
|
16
|
+
== Recommend way of installing JRuby
|
17
|
+
|
18
|
+
1. Install RVM: http://rvm.beginrescueend.com/
|
19
|
+
2. Install Jruby using rvm: rvm install jruby
|
20
|
+
3. Switch ruby to JRuby: rvm use jruby
|
21
|
+
|
22
|
+
== Getting Started
|
23
|
+
|
24
|
+
* functional_example_spec includes examples of basic operations in neo4j like creating, retrieving and updating nodes along with simple traversal examples.
|
25
|
+
* Neo4j API: http://api.neo4j.org/current/org/neo4j/api/core/package-summary.html
|
26
|
+
|
27
|
+
Basic Node creation:
|
28
|
+
|
29
|
+
Neo4jr::DB.execute do |neo|
|
30
|
+
node = neo.createNode
|
31
|
+
node[:name] = 'Deiters, Matt'
|
32
|
+
end
|
33
|
+
|
34
|
+
Retrieve a Node:
|
35
|
+
|
36
|
+
Neo4jr::DB.execute do |neo|
|
37
|
+
node = neo.getNodeById(1234)
|
38
|
+
end
|
39
|
+
|
40
|
+
Traverse Database from a node:
|
41
|
+
|
42
|
+
Neo4jr::DB.execute do |neo|
|
43
|
+
philip_seymour_hoffman = neo.getNodeById(1102)
|
44
|
+
|
45
|
+
order = Neo4jr::Order::BREADTH_FIRST
|
46
|
+
stop_when = Neo4jr::StopEvaluator::END_OF_GRAPH
|
47
|
+
return_when = Neo4jr::ReturnableEvaluator::ALL
|
48
|
+
relationships = Neo4jr::RelationshipType.outgoing(:acted_in)
|
49
|
+
|
50
|
+
traverser = philip_seymour_hoffman.traverse(order, stop_when, return_when, relationships_of_type)
|
51
|
+
traverser.each do |node|
|
52
|
+
#...
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
|
57
|
+
== Contributors
|
58
|
+
|
59
|
+
====Matthew Deiters
|
60
|
+
* Twitter : http://twitter.com/mdeiters
|
61
|
+
* GitHub : https://github.com/mdeiters
|
62
|
+
* LinkedIn : http://www.linkedin.com/in/matthewdeiters
|
63
|
+
* Blog : http://www.theagiledeveloper.com
|
64
|
+
|
65
|
+
== Copyright
|
66
|
+
|
67
|
+
Copyright (c) 2009 Matthew Deiters. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "neo4jr-simple"
|
8
|
+
gem.summary = %Q{A simple, ready to go JRuby wrapper for the Neo4j graph database engine.}
|
9
|
+
gem.description = %Q{Nothing more then Neo4j and Ruby goodness}
|
10
|
+
gem.email = "matthew_deiters@mckinsey.com"
|
11
|
+
gem.homepage = "http://github.com/mdeiters/neo4jr-simple"
|
12
|
+
gem.authors = ["Matthew Deiters"]
|
13
|
+
gem.add_development_dependency "rspec", ">= 1.2.9"
|
14
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
15
|
+
end
|
16
|
+
Jeweler::GemcutterTasks.new
|
17
|
+
rescue LoadError
|
18
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
19
|
+
end
|
20
|
+
|
21
|
+
require 'spec/rake/spectask'
|
22
|
+
Spec::Rake::SpecTask.new(:spec) do |spec|
|
23
|
+
spec.libs << 'lib' << 'spec'
|
24
|
+
spec.spec_files = FileList['spec/**/*_spec.rb']
|
25
|
+
end
|
26
|
+
|
27
|
+
Spec::Rake::SpecTask.new(:rcov) do |spec|
|
28
|
+
spec.libs << 'lib' << 'spec'
|
29
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
30
|
+
spec.rcov = true
|
31
|
+
end
|
32
|
+
|
33
|
+
task :spec => :check_dependencies
|
34
|
+
|
35
|
+
task :default => :spec
|
36
|
+
|
37
|
+
require 'rake/rdoctask'
|
38
|
+
Rake::RDocTask.new do |rdoc|
|
39
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
40
|
+
|
41
|
+
rdoc.rdoc_dir = 'rdoc'
|
42
|
+
rdoc.title = "neo4jr-simple #{version}"
|
43
|
+
rdoc.rdoc_files.include('README*')
|
44
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
45
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
Binary file
|
Binary file
|
Binary file
|
@@ -0,0 +1,18 @@
|
|
1
|
+
include Java
|
2
|
+
|
3
|
+
module Neo4j
|
4
|
+
require 'jars/neo-1.0-b9.jar'
|
5
|
+
require 'jars/shell-1.0-b9.jar'
|
6
|
+
require 'jars/jta-1_1.jar'
|
7
|
+
end
|
8
|
+
|
9
|
+
require 'neo4jr/configuration'
|
10
|
+
require 'neo4jr/db'
|
11
|
+
require 'neo4jr/relationship_type'
|
12
|
+
require 'neo4jr/node_extension'
|
13
|
+
require 'neo4jr/traverser_extension'
|
14
|
+
require 'neo4jr/returnable_evaluator'
|
15
|
+
require 'neo4jr/stop_evaluator'
|
16
|
+
require 'neo4jr/order'
|
17
|
+
require 'neo4jr/direction'
|
18
|
+
require 'neo4jr/version'
|
data/lib/neo4jr/db.rb
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
module Neo4jr
|
2
|
+
class DB
|
3
|
+
class << self
|
4
|
+
def instance
|
5
|
+
@neo ||= begin
|
6
|
+
neo = org.neo4j.api.core.EmbeddedNeo.new(Configuration.database_path)
|
7
|
+
at_exit do
|
8
|
+
neo.shutdown
|
9
|
+
end
|
10
|
+
neo
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def getNodeById(node_id)
|
15
|
+
n = nil
|
16
|
+
execute do |neo|
|
17
|
+
n = neo.getNodeById(node_id)
|
18
|
+
end
|
19
|
+
return n
|
20
|
+
end
|
21
|
+
|
22
|
+
def execute
|
23
|
+
neo = instance
|
24
|
+
transaction = neo.beginTx();
|
25
|
+
begin
|
26
|
+
yield neo
|
27
|
+
transaction.success
|
28
|
+
rescue Exception => e
|
29
|
+
transaction.failure
|
30
|
+
raise e
|
31
|
+
ensure
|
32
|
+
transaction.finish
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def node_count
|
37
|
+
instance.getConfig().getNeoModule().getNodeManager().getNumberOfIdsInUse(org.neo4j.api.core.Node.java_class)
|
38
|
+
end
|
39
|
+
|
40
|
+
def stats
|
41
|
+
info = ['== Database Stats ==']
|
42
|
+
info << "Path: #{Configuration.database_path}"
|
43
|
+
info << "Nodes: #{node_count}"
|
44
|
+
info << '===================='
|
45
|
+
info.join("\n")
|
46
|
+
end
|
47
|
+
|
48
|
+
def to_s
|
49
|
+
stats
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# Extends the Node class with a hash style accessor methods to the node's properties
|
2
|
+
org.neo4j.api.core.Node.java_class.ruby_class.class_eval do
|
3
|
+
|
4
|
+
def id
|
5
|
+
getId
|
6
|
+
end
|
7
|
+
|
8
|
+
# Example:
|
9
|
+
# node[:name] #=> 'Matt'
|
10
|
+
#
|
11
|
+
def [](arg)
|
12
|
+
get_property(arg.to_s)
|
13
|
+
end
|
14
|
+
|
15
|
+
# Example:
|
16
|
+
# node[:name] = 'Matt'
|
17
|
+
#
|
18
|
+
def []=(arg, value)
|
19
|
+
set_property(arg.to_s, value)
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
data/lib/neo4jr/order.rb
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
module Neo4jr
|
2
|
+
class RelationshipType
|
3
|
+
include org.neo4j.api.core.RelationshipType
|
4
|
+
|
5
|
+
@@names = {}
|
6
|
+
|
7
|
+
class << self
|
8
|
+
def instance(name)
|
9
|
+
return @@names[name] if @@names.include?(name)
|
10
|
+
@@names[name] = RelationshipType.new(name)
|
11
|
+
end
|
12
|
+
|
13
|
+
def outgoing(type)
|
14
|
+
covert_to_relationship_type(Neo4jr::Direction::OUTGOING, type)
|
15
|
+
end
|
16
|
+
|
17
|
+
def incoming(type)
|
18
|
+
covert_to_relationship_type(Neo4jr::Direction::INCOMING, type)
|
19
|
+
end
|
20
|
+
|
21
|
+
def both(type)
|
22
|
+
covert_to_relationship_type(Neo4jr::Direction::BOTH, type)
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
def covert_to_relationship_type(direction, type)
|
27
|
+
[ Neo4jr::RelationshipType.new(type.to_s),
|
28
|
+
direction
|
29
|
+
].to_java(:object)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def to_s
|
34
|
+
self.class.to_s + " name='#{@name}'"
|
35
|
+
end
|
36
|
+
|
37
|
+
def name
|
38
|
+
@name
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
def initialize(name)
|
44
|
+
@name = name.to_s
|
45
|
+
raise ArgumentError.new("Expect type of relationship to be a name of at least one character") if @name.empty?
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module Neo4jr
|
2
|
+
# SEE: http://api.neo4j.org/current/org/neo4j/api/core/ReturnableEvaluator.html
|
3
|
+
class ReturnableEvaluator
|
4
|
+
ALL = org.neo4j.api.core.ReturnableEvaluator.ALL
|
5
|
+
ALL_BUT_START_NODE = org.neo4j.api.core.ReturnableEvaluator.ALL_BUT_START_NODE
|
6
|
+
|
7
|
+
# Creates a new ReturnableEvaluator on the fly that delgates to the passed in block to use with the traverse method.
|
8
|
+
# The block should return either true or false
|
9
|
+
# See http://api.neo4j.org/current/org/neo4j/api/core/ReturnableEvaluator.html#isReturnableNode(org.neo4j.api.core.TraversalPosition)
|
10
|
+
#
|
11
|
+
# Examples:
|
12
|
+
#
|
13
|
+
# Return.when do |current_position|
|
14
|
+
# current_position.depth > 3 && current_position.previousNode[:active] == false
|
15
|
+
# end
|
16
|
+
#
|
17
|
+
def self.when(&block)
|
18
|
+
instance = new
|
19
|
+
instance.instance_variable_set(:@evaluator_block, block)
|
20
|
+
instance.instance_eval do
|
21
|
+
def isReturnableNode(position)
|
22
|
+
@evaluator_block.call(position)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
instance
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
Return = ReturnableEvaluator
|
30
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module Neo4jr
|
2
|
+
# SEE: http://api.neo4j.org/current/org/neo4j/api/core/StopEvaluator.html
|
3
|
+
class StopEvaluator
|
4
|
+
DEPTH_ONE = org.neo4j.api.core.StopEvaluator::DEPTH_ONE
|
5
|
+
END_OF_GRAPH = org.neo4j.api.core.StopEvaluator::END_OF_GRAPH
|
6
|
+
END_OF_NETWORK = org.neo4j.api.core.StopEvaluator::END_OF_NETWORK
|
7
|
+
|
8
|
+
# Creates a new StopEvaluator on the fly that delgates to the passed in block to use with the traverse method.
|
9
|
+
# The block should return either true or false
|
10
|
+
# See http://api.neo4j.org/current/org/neo4j/api/core/StopEvaluator.html#isStopNode(org.neo4j.api.core.TraversalPosition)
|
11
|
+
#
|
12
|
+
# Examples:
|
13
|
+
#
|
14
|
+
# Stop.when do |current_position|
|
15
|
+
# current_position.depth > 3 && current_position.previousNode[:active] == false
|
16
|
+
# end
|
17
|
+
#
|
18
|
+
def self.when(&block)
|
19
|
+
instance = new
|
20
|
+
instance.instance_variable_set(:@evaluator_block, block)
|
21
|
+
instance.instance_eval do
|
22
|
+
def isStopNode(position)
|
23
|
+
@evaluator_block.call(position)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
instance
|
27
|
+
end
|
28
|
+
|
29
|
+
# Creates a new StopEvaluator on the fly that will stop traversing the graph when the depth specified is reached
|
30
|
+
#
|
31
|
+
# Examples:
|
32
|
+
#
|
33
|
+
# Stop.at(4)
|
34
|
+
#
|
35
|
+
def self.at(depth)
|
36
|
+
self.when do |position|
|
37
|
+
position.depth >= depth
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
Stop = StopEvaluator
|
43
|
+
end
|
@@ -0,0 +1,99 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{neo4jr-simple}
|
8
|
+
s.version = "0.1.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Matthew Deiters"]
|
12
|
+
s.date = %q{2009-12-18}
|
13
|
+
s.description = %q{Nothing more then Neo4j and Ruby goodness}
|
14
|
+
s.email = %q{matthew_deiters@mckinsey.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE",
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
".gitignore",
|
22
|
+
"LICENSE",
|
23
|
+
"README.rdoc",
|
24
|
+
"Rakefile",
|
25
|
+
"VERSION",
|
26
|
+
"lib/jars/jta-1_1.jar",
|
27
|
+
"lib/jars/neo-1.0-b9.jar",
|
28
|
+
"lib/jars/shell-1.0-b9.jar",
|
29
|
+
"lib/neo4jr-simple.rb",
|
30
|
+
"lib/neo4jr/configuration.rb",
|
31
|
+
"lib/neo4jr/db.rb",
|
32
|
+
"lib/neo4jr/direction.rb",
|
33
|
+
"lib/neo4jr/node_extension.rb",
|
34
|
+
"lib/neo4jr/order.rb",
|
35
|
+
"lib/neo4jr/relationship_type.rb",
|
36
|
+
"lib/neo4jr/returnable_evaluator.rb",
|
37
|
+
"lib/neo4jr/stop_evaluator.rb",
|
38
|
+
"lib/neo4jr/traverser_extension.rb",
|
39
|
+
"lib/neo4jr/version.rb",
|
40
|
+
"neo4jr-simple.gemspec",
|
41
|
+
"spec/db_spec.rb",
|
42
|
+
"spec/functional_example_spec.rb",
|
43
|
+
"spec/node_extension_spec.rb",
|
44
|
+
"spec/returnable_evaluator_spec.rb",
|
45
|
+
"spec/spec.opts",
|
46
|
+
"spec/spec_helper.rb",
|
47
|
+
"spec/stop_evaluator_spec.rb",
|
48
|
+
"spec/test-imdb-database/active_tx_log",
|
49
|
+
"spec/test-imdb-database/neostore",
|
50
|
+
"spec/test-imdb-database/neostore.id",
|
51
|
+
"spec/test-imdb-database/neostore.nodestore.db",
|
52
|
+
"spec/test-imdb-database/neostore.nodestore.db.id",
|
53
|
+
"spec/test-imdb-database/neostore.propertystore.db",
|
54
|
+
"spec/test-imdb-database/neostore.propertystore.db.arrays",
|
55
|
+
"spec/test-imdb-database/neostore.propertystore.db.arrays.id",
|
56
|
+
"spec/test-imdb-database/neostore.propertystore.db.id",
|
57
|
+
"spec/test-imdb-database/neostore.propertystore.db.index",
|
58
|
+
"spec/test-imdb-database/neostore.propertystore.db.index.id",
|
59
|
+
"spec/test-imdb-database/neostore.propertystore.db.index.keys",
|
60
|
+
"spec/test-imdb-database/neostore.propertystore.db.index.keys.id",
|
61
|
+
"spec/test-imdb-database/neostore.propertystore.db.strings",
|
62
|
+
"spec/test-imdb-database/neostore.propertystore.db.strings.id",
|
63
|
+
"spec/test-imdb-database/neostore.relationshipstore.db",
|
64
|
+
"spec/test-imdb-database/neostore.relationshipstore.db.id",
|
65
|
+
"spec/test-imdb-database/neostore.relationshiptypestore.db",
|
66
|
+
"spec/test-imdb-database/neostore.relationshiptypestore.db.id",
|
67
|
+
"spec/test-imdb-database/neostore.relationshiptypestore.db.names",
|
68
|
+
"spec/test-imdb-database/neostore.relationshiptypestore.db.names.id",
|
69
|
+
"spec/test-imdb-database/nioneo_logical.log.active",
|
70
|
+
"spec/test-imdb-database/tm_tx_log.1"
|
71
|
+
]
|
72
|
+
s.homepage = %q{http://github.com/mdeiters/neo4jr-simple}
|
73
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
74
|
+
s.require_paths = ["lib"]
|
75
|
+
s.rubygems_version = %q{1.3.5}
|
76
|
+
s.summary = %q{A simple, ready to go JRuby wrapper for the Neo4j graph database engine.}
|
77
|
+
s.test_files = [
|
78
|
+
"spec/db_spec.rb",
|
79
|
+
"spec/functional_example_spec.rb",
|
80
|
+
"spec/node_extension_spec.rb",
|
81
|
+
"spec/returnable_evaluator_spec.rb",
|
82
|
+
"spec/spec_helper.rb",
|
83
|
+
"spec/stop_evaluator_spec.rb"
|
84
|
+
]
|
85
|
+
|
86
|
+
if s.respond_to? :specification_version then
|
87
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
88
|
+
s.specification_version = 3
|
89
|
+
|
90
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
91
|
+
s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
|
92
|
+
else
|
93
|
+
s.add_dependency(%q<rspec>, [">= 1.2.9"])
|
94
|
+
end
|
95
|
+
else
|
96
|
+
s.add_dependency(%q<rspec>, [">= 1.2.9"])
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
data/spec/db_spec.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe Neo4jr::DB do
|
4
|
+
it 'should fail the transaction if an error happens and then propgate the original exception' do
|
5
|
+
lambda{
|
6
|
+
Neo4jr::DB.execute do |neo|
|
7
|
+
raise SystemCallError, 'testing'
|
8
|
+
end
|
9
|
+
}.should raise_error(SystemCallError)
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe "Neo4j Working Examples" do
|
4
|
+
it "queries all nodes" do
|
5
|
+
Neo4jr::DB.execute do |neo|
|
6
|
+
hanks = neo.all_nodes.select{|people| people if people.get_property('name').match(/Hanks/) rescue nil }
|
7
|
+
hanks.should have(2).nodes
|
8
|
+
hanks.first.get_property('name').should == 'Hanks, Tom'
|
9
|
+
hanks.last.get_property('name').should == 'Hanks, Jay (I)'
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
describe 'cruding a node' do
|
14
|
+
let(:node_id) do
|
15
|
+
node_id = nil
|
16
|
+
Neo4jr::DB.execute do |neo|
|
17
|
+
node = neo.createNode
|
18
|
+
node[:name] = 'Deiters, Matt'
|
19
|
+
node_id = node.getId
|
20
|
+
end
|
21
|
+
node_id
|
22
|
+
end
|
23
|
+
|
24
|
+
after :each do
|
25
|
+
Neo4jr::DB.execute do |neo|
|
26
|
+
node = neo.getNodeById(node_id)
|
27
|
+
node.delete
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'can later read the node' do
|
32
|
+
node = Neo4jr::DB.getNodeById(node_id)
|
33
|
+
node[:name].should == 'Deiters, Matt'
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'can traverse a node using the raw API' do
|
38
|
+
Neo4jr::DB.execute do |neo|
|
39
|
+
# Node[1102]: Hoffman, Philip Seymour
|
40
|
+
# Node[1104]: Hoffman, Dustin
|
41
|
+
philip_seymour_hoffman = neo.getNodeById(1102)
|
42
|
+
|
43
|
+
order = Neo4jr::Order::BREADTH_FIRST
|
44
|
+
stop_when = Neo4jr::StopEvaluator::END_OF_GRAPH
|
45
|
+
return_when = Neo4jr::ReturnableEvaluator::ALL
|
46
|
+
relationship = Neo4jr::RelationshipType.outgoing(:acted_in)
|
47
|
+
|
48
|
+
traverser = philip_seymour_hoffman.traverse(order, stop_when, return_when, relationship)
|
49
|
+
# traverser.each do |person_or_movie|
|
50
|
+
# puts person_or_movie.get_property('title') rescue person_or_movie.get_property('name')
|
51
|
+
# end
|
52
|
+
traverser.size.should == 15
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe 'node extension' do
|
4
|
+
|
5
|
+
it "adds [] read accessor method for properties" do
|
6
|
+
tom_hanks = Neo4jr::DB.instance.getNodeById(893)
|
7
|
+
tom_hanks[:name].should == 'Hanks, Tom'
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'adds [] setter accessor method for properties' do
|
11
|
+
Neo4jr::DB.execute do |neo|
|
12
|
+
tom_hanks = neo.getNodeById(893)
|
13
|
+
tom_hanks[:testing] = '123'
|
14
|
+
tom_hanks[:testing].should == '123'
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe Neo4jr::ReturnableEvaluator do
|
4
|
+
it 'should alias class with class Return' do
|
5
|
+
Neo4jr::Return::ALL.should == Neo4jr::ReturnableEvaluator::ALL
|
6
|
+
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'should create dynamic evaluators on the fly' do
|
10
|
+
dynamic_evaluator = Neo4jr::Return.when do |postion|
|
11
|
+
true if postion == :test
|
12
|
+
end
|
13
|
+
dynamic_evaluator.isReturnableNode(:test).should == true
|
14
|
+
end
|
15
|
+
end
|
data/spec/spec.opts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
2
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
3
|
+
require 'neo4jr-simple'
|
4
|
+
require 'spec'
|
5
|
+
require 'spec/autorun'
|
6
|
+
|
7
|
+
Neo4jr::Configuration.database_path = File.join(File.expand_path(File.dirname(__FILE__)), 'test-imdb-database')
|
8
|
+
puts Neo4jr::DB
|
9
|
+
|
10
|
+
Spec::Runner.configure do |config|
|
11
|
+
|
12
|
+
end
|
13
|
+
|
14
|
+
|
15
|
+
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe Neo4jr::StopEvaluator do
|
4
|
+
it 'should alias class with class Stop' do
|
5
|
+
Neo4jr::Stop::DEPTH_ONE.should == Neo4jr::StopEvaluator::DEPTH_ONE
|
6
|
+
end
|
7
|
+
|
8
|
+
it 'should create dynamic evaluators on the fly' do
|
9
|
+
dynamic_evaluator = Neo4jr::Stop.when do |postion|
|
10
|
+
true if postion == :test
|
11
|
+
end
|
12
|
+
dynamic_evaluator.isStopNode(:test).should == true
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'should create a dynamic evaluator for a number' do
|
16
|
+
evaluator = Neo4jr::Stop.at(2)
|
17
|
+
mock_position = Object.new
|
18
|
+
mock_position.instance_eval do
|
19
|
+
def depth
|
20
|
+
1
|
21
|
+
end
|
22
|
+
end
|
23
|
+
evaluator.isStopNode(mock_position).should be_false
|
24
|
+
|
25
|
+
mock_position.instance_eval do
|
26
|
+
def depth
|
27
|
+
2
|
28
|
+
end
|
29
|
+
end
|
30
|
+
evaluator.isStopNode(mock_position).should be_true
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
tm_tx_log.1
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
metadata
ADDED
@@ -0,0 +1,120 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: neo4jr-simple
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Matthew Deiters
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-12-18 00:00:00 -08:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: rspec
|
17
|
+
type: :development
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 1.2.9
|
24
|
+
version:
|
25
|
+
description: Nothing more then Neo4j and Ruby goodness
|
26
|
+
email: matthew_deiters@mckinsey.com
|
27
|
+
executables: []
|
28
|
+
|
29
|
+
extensions: []
|
30
|
+
|
31
|
+
extra_rdoc_files:
|
32
|
+
- LICENSE
|
33
|
+
- README.rdoc
|
34
|
+
files:
|
35
|
+
- .document
|
36
|
+
- .gitignore
|
37
|
+
- LICENSE
|
38
|
+
- README.rdoc
|
39
|
+
- Rakefile
|
40
|
+
- VERSION
|
41
|
+
- lib/jars/jta-1_1.jar
|
42
|
+
- lib/jars/neo-1.0-b9.jar
|
43
|
+
- lib/jars/shell-1.0-b9.jar
|
44
|
+
- lib/neo4jr-simple.rb
|
45
|
+
- lib/neo4jr/configuration.rb
|
46
|
+
- lib/neo4jr/db.rb
|
47
|
+
- lib/neo4jr/direction.rb
|
48
|
+
- lib/neo4jr/node_extension.rb
|
49
|
+
- lib/neo4jr/order.rb
|
50
|
+
- lib/neo4jr/relationship_type.rb
|
51
|
+
- lib/neo4jr/returnable_evaluator.rb
|
52
|
+
- lib/neo4jr/stop_evaluator.rb
|
53
|
+
- lib/neo4jr/traverser_extension.rb
|
54
|
+
- lib/neo4jr/version.rb
|
55
|
+
- neo4jr-simple.gemspec
|
56
|
+
- spec/db_spec.rb
|
57
|
+
- spec/functional_example_spec.rb
|
58
|
+
- spec/node_extension_spec.rb
|
59
|
+
- spec/returnable_evaluator_spec.rb
|
60
|
+
- spec/spec.opts
|
61
|
+
- spec/spec_helper.rb
|
62
|
+
- spec/stop_evaluator_spec.rb
|
63
|
+
- spec/test-imdb-database/active_tx_log
|
64
|
+
- spec/test-imdb-database/neostore
|
65
|
+
- spec/test-imdb-database/neostore.id
|
66
|
+
- spec/test-imdb-database/neostore.nodestore.db
|
67
|
+
- spec/test-imdb-database/neostore.nodestore.db.id
|
68
|
+
- spec/test-imdb-database/neostore.propertystore.db
|
69
|
+
- spec/test-imdb-database/neostore.propertystore.db.arrays
|
70
|
+
- spec/test-imdb-database/neostore.propertystore.db.arrays.id
|
71
|
+
- spec/test-imdb-database/neostore.propertystore.db.id
|
72
|
+
- spec/test-imdb-database/neostore.propertystore.db.index
|
73
|
+
- spec/test-imdb-database/neostore.propertystore.db.index.id
|
74
|
+
- spec/test-imdb-database/neostore.propertystore.db.index.keys
|
75
|
+
- spec/test-imdb-database/neostore.propertystore.db.index.keys.id
|
76
|
+
- spec/test-imdb-database/neostore.propertystore.db.strings
|
77
|
+
- spec/test-imdb-database/neostore.propertystore.db.strings.id
|
78
|
+
- spec/test-imdb-database/neostore.relationshipstore.db
|
79
|
+
- spec/test-imdb-database/neostore.relationshipstore.db.id
|
80
|
+
- spec/test-imdb-database/neostore.relationshiptypestore.db
|
81
|
+
- spec/test-imdb-database/neostore.relationshiptypestore.db.id
|
82
|
+
- spec/test-imdb-database/neostore.relationshiptypestore.db.names
|
83
|
+
- spec/test-imdb-database/neostore.relationshiptypestore.db.names.id
|
84
|
+
- spec/test-imdb-database/nioneo_logical.log.active
|
85
|
+
- spec/test-imdb-database/tm_tx_log.1
|
86
|
+
has_rdoc: true
|
87
|
+
homepage: http://github.com/mdeiters/neo4jr-simple
|
88
|
+
licenses: []
|
89
|
+
|
90
|
+
post_install_message:
|
91
|
+
rdoc_options:
|
92
|
+
- --charset=UTF-8
|
93
|
+
require_paths:
|
94
|
+
- lib
|
95
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
96
|
+
requirements:
|
97
|
+
- - ">="
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: "0"
|
100
|
+
version:
|
101
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
102
|
+
requirements:
|
103
|
+
- - ">="
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
version: "0"
|
106
|
+
version:
|
107
|
+
requirements: []
|
108
|
+
|
109
|
+
rubyforge_project:
|
110
|
+
rubygems_version: 1.3.5
|
111
|
+
signing_key:
|
112
|
+
specification_version: 3
|
113
|
+
summary: A simple, ready to go JRuby wrapper for the Neo4j graph database engine.
|
114
|
+
test_files:
|
115
|
+
- spec/db_spec.rb
|
116
|
+
- spec/functional_example_spec.rb
|
117
|
+
- spec/node_extension_spec.rb
|
118
|
+
- spec/returnable_evaluator_spec.rb
|
119
|
+
- spec/spec_helper.rb
|
120
|
+
- spec/stop_evaluator_spec.rb
|