rom-neo4j 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +13 -3
- data/TODO.md +28 -0
- data/lib/rom/neo4j/support/core_ext.rb +14 -34
- data/lib/rom/neo4j/version.rb +1 -1
- data/rom-neo4j.gemspec +2 -1
- data/spec/integration/adapter_spec.rb +9 -2
- metadata +22 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0223ebc6313d58b19a54c660a159abe607ebf078
|
4
|
+
data.tar.gz: 0db461806b855450fc74c1d655fb3322ad0e1ab8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f70b19f16c66fb7278dda9a1793fabb65a6bb27e63f0f6a356ffebe3bc67d88eb7adeb66332df8f18714c8f5f972060f4f172a04208f755ea7fd1825fe4ff25e
|
7
|
+
data.tar.gz: 60ce87a5c86c3a8833068977379ca257545fbf55b3b094aa7bfb52f27b6ee990e22783159c079d36e487058d4a47a37c3ef99501196f4c601f88b548b66a3338
|
data/README.md
CHANGED
@@ -4,12 +4,24 @@ Map objects returned from Neo4j graph traversals using the [Ruby Object Mapper](
|
|
4
4
|
|
5
5
|
## Status
|
6
6
|
|
7
|
-
Incomplete experimental sketch
|
7
|
+
**Incomplete experimental sketch.**
|
8
8
|
|
9
9
|
The adapter spec passes with the generic movies dataset distributed with Neo4j, but that's about all at this point.
|
10
10
|
|
11
11
|
## Install
|
12
12
|
|
13
|
+
Install with Rubygems:
|
14
|
+
|
15
|
+
```
|
16
|
+
gem install rom-neo4j
|
17
|
+
```
|
18
|
+
|
19
|
+
Or add the dependency to your `Gemfile`:
|
20
|
+
|
21
|
+
```
|
22
|
+
gem 'rom-neo4j'
|
23
|
+
```
|
24
|
+
|
13
25
|
Right now, the fastest way to get started is to run the tests.
|
14
26
|
|
15
27
|
You’ll need to have Neo4j installed on your system. If it’s not already running, start the database server with:
|
@@ -38,7 +50,6 @@ setup.relation(:movies) do
|
|
38
50
|
def titled(title)
|
39
51
|
where('m.title' => title)
|
40
52
|
end
|
41
|
-
|
42
53
|
end
|
43
54
|
|
44
55
|
movie = rom.read(:movies).titled('The Matrix').first
|
@@ -56,7 +67,6 @@ setup.relation(:directors) do
|
|
56
67
|
def by_movie(title)
|
57
68
|
where('movie.title' => title)
|
58
69
|
end
|
59
|
-
|
60
70
|
end
|
61
71
|
|
62
72
|
director = rom.read(:directors).by_movie('RescueDawn').first
|
data/TODO.md
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# TODO
|
2
|
+
|
3
|
+
## Features
|
4
|
+
|
5
|
+
- Add command wrapper
|
6
|
+
- Surface write capabilities from Neo4j::Core
|
7
|
+
- Support embedded mode (JRuby only)
|
8
|
+
|
9
|
+
## API
|
10
|
+
|
11
|
+
- Class method/DSL/convention for relation shared SELECT/MATCH
|
12
|
+
- Wrapper with prefix/select (?)
|
13
|
+
|
14
|
+
## Mappers
|
15
|
+
|
16
|
+
- Find out why prefix mapping isn't working
|
17
|
+
|
18
|
+
## Dataset
|
19
|
+
|
20
|
+
- Unit test of cypher query building
|
21
|
+
- Documentation of instance methods
|
22
|
+
|
23
|
+
## Housekeeping
|
24
|
+
|
25
|
+
- Add LICENSE
|
26
|
+
- Tidy up README
|
27
|
+
- Add Travis CI hooks
|
28
|
+
- Configurable host URI in tests
|
@@ -1,44 +1,24 @@
|
|
1
1
|
# Extensions to the Neo4j::Core library making it easier to integrate with ROM.
|
2
2
|
module Neo4j
|
3
3
|
module Core
|
4
|
-
|
4
|
+
UnsupportedDriver = Class.new(StandardError)
|
5
|
+
|
6
|
+
# DSL for generating Cypher queries and enumerating their results.
|
5
7
|
#
|
6
8
|
# @see http://www.rubydoc.info/gems/neo4j-core/Neo4j/Core/Query
|
7
9
|
class Query
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
end
|
18
|
-
module Server
|
19
|
-
class CypherResponse
|
20
|
-
# Coerces result objects from structs to hashes in results.
|
21
|
-
class HashEnumeration
|
22
|
-
def each(&block)
|
23
|
-
@response.each_data_row do |row|
|
24
|
-
yield(row.each_with_index.each_with_object(struct.new) do |(value, i), result|
|
25
|
-
result[columns[i].to_sym] = value
|
26
|
-
end.to_h)
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
# Coerces result objects from structs to hashes in results.
|
31
|
-
def to_node_enumeration(cypher = '', session = Neo4j::Session.current)
|
32
|
-
Enumerator.new do |yielder|
|
33
|
-
@result_index = 0
|
34
|
-
to_struct_enumeration(cypher).each do |row|
|
35
|
-
@row_index = 0
|
36
|
-
yielder << row.each_pair.each_with_object(@struct.new) do |(column, value), result|
|
37
|
-
result[column] = map_row_value(value, session)
|
38
|
-
@row_index += 1
|
39
|
-
end.to_h
|
40
|
-
@result_index += 1
|
10
|
+
def each
|
11
|
+
return enum_for(:each) unless block_given?
|
12
|
+
|
13
|
+
response = self.response
|
14
|
+
columns = response.columns.map { |c| c.to_sym }
|
15
|
+
|
16
|
+
if response.is_a?(Neo4j::Server::CypherResponse)
|
17
|
+
response.data.map do |row|
|
18
|
+
yield Hash[columns.zip(row)]
|
41
19
|
end
|
20
|
+
else
|
21
|
+
raise Neo4j::Core::UnsupportedDriver, 'Neo4j::Embedded is not supported (yet)'
|
42
22
|
end
|
43
23
|
end
|
44
24
|
end
|
data/lib/rom/neo4j/version.rb
CHANGED
data/rom-neo4j.gemspec
CHANGED
@@ -19,9 +19,10 @@ Gem::Specification.new do |spec|
|
|
19
19
|
spec.require_paths = ['lib']
|
20
20
|
|
21
21
|
spec.add_runtime_dependency 'rom', '~> 0.6'
|
22
|
-
spec.add_runtime_dependency 'neo4j-core', '
|
22
|
+
spec.add_runtime_dependency 'neo4j-core', '4.0.1'
|
23
23
|
|
24
24
|
spec.add_development_dependency 'bundler'
|
25
25
|
spec.add_development_dependency 'rake'
|
26
|
+
spec.add_development_dependency 'rspec'
|
26
27
|
spec.add_development_dependency 'rubocop', '~> 0.28.0'
|
27
28
|
end
|
@@ -15,14 +15,18 @@ describe 'Neo4j adapter' do
|
|
15
15
|
def by_title(title)
|
16
16
|
where('m.title' => title)
|
17
17
|
end
|
18
|
+
|
19
|
+
def by_year(year)
|
20
|
+
where('m.released' => year)
|
21
|
+
end
|
18
22
|
end
|
19
23
|
|
20
24
|
setup.mappers do
|
21
25
|
define(:movies) do
|
22
26
|
relation :movies
|
23
27
|
model name: 'Movie'
|
24
|
-
#prefix :m
|
25
|
-
#prefix_separator '.'
|
28
|
+
# prefix :m
|
29
|
+
# prefix_separator '.'
|
26
30
|
attribute :title
|
27
31
|
attribute :released
|
28
32
|
attribute :tagline
|
@@ -45,6 +49,9 @@ describe 'Neo4j adapter' do
|
|
45
49
|
end
|
46
50
|
end
|
47
51
|
|
52
|
+
it 'maps movies #by_year' do
|
53
|
+
expect(movies.by_year(1999).to_a.count).to eq(4)
|
54
|
+
end
|
48
55
|
end
|
49
56
|
|
50
57
|
context 'with directors relation and mapper' do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rom-neo4j
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mark Rickerby
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-04-
|
11
|
+
date: 2015-04-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rom
|
@@ -28,16 +28,16 @@ dependencies:
|
|
28
28
|
name: neo4j-core
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - '='
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: 4.0.1
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - '='
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
40
|
+
version: 4.0.1
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: bundler
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -66,6 +66,20 @@ dependencies:
|
|
66
66
|
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
69
83
|
- !ruby/object:Gem::Dependency
|
70
84
|
name: rubocop
|
71
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -90,6 +104,7 @@ files:
|
|
90
104
|
- ".gitignore"
|
91
105
|
- Gemfile
|
92
106
|
- README.md
|
107
|
+
- TODO.md
|
93
108
|
- lib/rom-neo4j.rb
|
94
109
|
- lib/rom/neo4j.rb
|
95
110
|
- lib/rom/neo4j/dataset.rb
|
@@ -122,7 +137,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
122
137
|
version: '0'
|
123
138
|
requirements: []
|
124
139
|
rubyforge_project:
|
125
|
-
rubygems_version: 2.
|
140
|
+
rubygems_version: 2.2.2
|
126
141
|
signing_key:
|
127
142
|
specification_version: 4
|
128
143
|
summary: Neo4j graph relations for Ruby Object Mapper
|