geoff 0.0.3.beta → 0.0.4
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/.rbenv-version +1 -0
- data/README.md +30 -24
- data/bin/autospec +16 -0
- data/bin/coderay +16 -0
- data/bin/erubis +16 -0
- data/bin/htmldiff +16 -0
- data/bin/ldiff +16 -0
- data/bin/neo4j-jars +16 -0
- data/bin/neo4j-shell +16 -0
- data/bin/neo4j-upgrade +16 -0
- data/bin/pry +16 -0
- data/bin/rackup +16 -0
- data/bin/rails +16 -0
- data/bin/rake +16 -0
- data/bin/rake2thor +16 -0
- data/bin/rdebug +16 -0
- data/bin/ri +16 -0
- data/bin/rspec +16 -0
- data/bin/thor +16 -0
- data/bin/tilt +16 -0
- data/geoff.gemspec +0 -1
- data/lib/geoff/children_dsl.rb +50 -3
- data/lib/geoff/container.rb +48 -8
- data/lib/geoff/importer.rb +1 -1
- data/lib/geoff/node_dsl.rb +29 -8
- data/lib/geoff/version.rb +2 -2
- data/lib/geoff.rb +85 -5
- data/spec/integration/children_dsl_spec.rb +9 -5
- data/spec/integration/geoff_spec.rb +171 -0
- data/spec/integration/node_dsl_spec.rb +98 -42
- data/spec/models/container_spec.rb +27 -0
- data/spec/models/geoff_spec.rb +138 -41
- data/spec/node_dsl_spec.rb +24 -0
- data/spec/spec_helper.rb +4 -1
- metadata +30 -11
- data/lib/geoff/neo4j_wrapper_dsl.rb +0 -50
- data/lib/geoff/neo4j_wrapper_validator.rb +0 -17
- data/spec/models/neo4j_wrapper_dsl_spec.rb +0 -86
- data/spec/models/neo4j_wrapper_validator_spec.rb +0 -28
data/spec/models/geoff_spec.rb
CHANGED
@@ -3,70 +3,167 @@ require 'neo4j'
|
|
3
3
|
require 'geoff'
|
4
4
|
|
5
5
|
describe Geoff do
|
6
|
-
|
7
|
-
include Neo4j::NodeMixin
|
8
|
-
end
|
9
|
-
class Cafe
|
10
|
-
include Neo4j::NodeMixin
|
11
|
-
end
|
6
|
+
before { stub_node_dsl_object_id }
|
12
7
|
|
13
|
-
|
14
|
-
include Neo4j::NodeMixin
|
15
|
-
end
|
8
|
+
context do
|
16
9
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
describe 'base nodes' do
|
10
|
+
class Branch
|
11
|
+
include Neo4j::NodeMixin
|
12
|
+
end
|
21
13
|
|
22
|
-
|
23
|
-
|
14
|
+
class Cafe
|
15
|
+
include Neo4j::NodeMixin
|
24
16
|
end
|
25
17
|
|
26
|
-
|
27
|
-
|
18
|
+
describe 'base nodes' do
|
19
|
+
|
20
|
+
let(:builder) do
|
21
|
+
Geoff(Cafe, Branch)
|
22
|
+
end
|
23
|
+
|
24
|
+
let(:expected_geoff) do
|
25
|
+
strip_whitespace <<-EOS
|
28
26
|
(ROOT)-[:Cafe]->(Cafe)
|
29
|
-
(ROOT)-[:Carrier]->(Carrier)
|
30
27
|
(ROOT)-[:Branch]->(Branch)
|
31
|
-
|
32
|
-
|
33
|
-
end
|
28
|
+
EOS
|
29
|
+
end
|
34
30
|
|
35
|
-
|
36
|
-
|
31
|
+
specify do
|
32
|
+
builder.to_s.should == expected_geoff
|
33
|
+
end
|
37
34
|
end
|
38
|
-
end
|
39
35
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
36
|
+
describe 'Geoff sugar' do
|
37
|
+
let(:node) do
|
38
|
+
Geoff(Branch) do
|
39
|
+
branch 'starbucks_branch' do
|
40
|
+
delay_time 15
|
41
|
+
end
|
45
42
|
end
|
46
43
|
end
|
47
|
-
end
|
48
44
|
|
49
|
-
|
50
|
-
|
45
|
+
let(:expected_geoff) do
|
46
|
+
strip_whitespace <<-EOS
|
51
47
|
(ROOT)-[:Branch]->(Branch)
|
52
48
|
(starbucks_branch) {"_classname":"Branch","delay_time":15}
|
53
49
|
(Branch)-[:all]->(starbucks_branch)
|
50
|
+
EOS
|
51
|
+
end
|
52
|
+
|
53
|
+
specify do
|
54
|
+
node.to_geoff.should == expected_geoff
|
55
|
+
end
|
56
|
+
|
57
|
+
specify do
|
58
|
+
pending 'not implemented'
|
59
|
+
->{
|
60
|
+
Geoff do
|
61
|
+
branch 'starbucks_branch' do
|
62
|
+
delay_time 15
|
63
|
+
end
|
64
|
+
end
|
65
|
+
}.should raise_error Geoff::MissingClassDefinition, "branch"
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
context do
|
71
|
+
let(:expected_geoff) do
|
72
|
+
strip_whitespace <<-EOS
|
73
|
+
(ROOT)-[:Sandwich]->(Sandwich)
|
74
|
+
(ROOT)-[:Cheese]->(Cheese)
|
75
|
+
(ROOT)-[:Egg]->(Egg)
|
54
76
|
EOS
|
55
77
|
end
|
56
78
|
|
57
|
-
|
58
|
-
|
79
|
+
class Sandwich
|
80
|
+
include Neo4j::NodeMixin
|
59
81
|
end
|
60
82
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
83
|
+
class Cafe
|
84
|
+
include Neo4j::NodeMixin
|
85
|
+
end
|
86
|
+
|
87
|
+
class Branch
|
88
|
+
include Neo4j::NodeMixin
|
89
|
+
end
|
90
|
+
|
91
|
+
|
92
|
+
class Cheese
|
93
|
+
include Neo4j::NodeMixin
|
94
|
+
end
|
95
|
+
|
96
|
+
class Egg
|
97
|
+
include Neo4j::NodeMixin
|
98
|
+
end
|
99
|
+
|
100
|
+
|
101
|
+
describe "#to_s" do
|
102
|
+
specify do
|
103
|
+
dsl = Geoff.new Sandwich, Cheese, Egg
|
104
|
+
dsl.to_s.should == dsl.to_geoff
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
describe "#to_geoff" do
|
109
|
+
it "outputs root node geoff syntax" do
|
110
|
+
dsl = Geoff.new(Sandwich, Cheese, Egg)
|
111
|
+
dsl.to_geoff.should == expected_geoff
|
112
|
+
end
|
113
|
+
|
114
|
+
specify do
|
115
|
+
->{Geoff.new 2 } .should raise_error ArgumentError
|
116
|
+
->{Geoff.new '' } .should raise_error ArgumentError
|
117
|
+
->{Geoff.new ['']}.should raise_error ArgumentError
|
118
|
+
->{Geoff.new [1]} .should raise_error ArgumentError
|
119
|
+
|
120
|
+
->{Geoff.new(Egg)}.should_not raise_error ArgumentError
|
121
|
+
end
|
122
|
+
|
123
|
+
|
124
|
+
context "with a block" do
|
125
|
+
let(:expected) {
|
126
|
+
strip_whitespace <<-EOS
|
127
|
+
(ROOT)-[:Cafe]->(Cafe)
|
128
|
+
(ROOT)-[:Branch]->(Branch)
|
129
|
+
(Starbucks) {"_classname":"Cafe"}
|
130
|
+
(Cafe)-[:all]->(Starbucks)
|
131
|
+
(starbucks_branch) {"_classname":"Branch"}
|
132
|
+
(Branch)-[:all]->(starbucks_branch)
|
133
|
+
(Starbucks)-[:owns]->(starbucks_branch)
|
134
|
+
EOS
|
135
|
+
}
|
136
|
+
|
137
|
+
specify "with parent node is root node, but no relationship,
|
138
|
+
don't create relationship to root node" do
|
139
|
+
Geoff.new(Cafe, Branch) do
|
140
|
+
cafe 'Starbucks' do
|
141
|
+
children 'owns' do
|
142
|
+
#create relationship to parent node of type owns (comes from children DSL)
|
143
|
+
branch 'starbucks_branch'
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
end.to_geoff.should == expected
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
describe 'called second time' do
|
152
|
+
let(:node) do
|
153
|
+
Geoff.new(Cafe) do
|
154
|
+
cafe 'Starbucks'
|
67
155
|
end
|
68
156
|
end
|
69
|
-
|
157
|
+
|
158
|
+
let(:expected_geoff) do
|
159
|
+
node.to_geoff
|
160
|
+
end
|
161
|
+
|
162
|
+
it 'returns same geoff as on first call' do
|
163
|
+
pending 'Not implemented yet'
|
164
|
+
node.to_geoff.should == expected_geoff
|
165
|
+
end
|
166
|
+
end
|
70
167
|
end
|
71
168
|
end
|
72
169
|
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'geoff/node_dsl'
|
3
|
+
|
4
|
+
describe NodeDsl do
|
5
|
+
subject { NodeDsl.new(node_name: 'starbucks') }
|
6
|
+
|
7
|
+
describe '#node_name' do
|
8
|
+
context 'in normal (non-test) use of builder' do
|
9
|
+
before do
|
10
|
+
subject.stub(:object_id).and_return 'egg'
|
11
|
+
end
|
12
|
+
|
13
|
+
its(:node_name) { should == 'starbucks_egg' }
|
14
|
+
end
|
15
|
+
|
16
|
+
context 'with object_id returning nil to make integration testing easier' do
|
17
|
+
before do
|
18
|
+
subject.stub(:object_id).and_return nil
|
19
|
+
end
|
20
|
+
|
21
|
+
its(:node_name) { should == 'starbucks' }
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: geoff
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
prerelease:
|
5
|
-
version: 0.0.
|
4
|
+
prerelease:
|
5
|
+
version: 0.0.4
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- David Rouchy
|
@@ -13,7 +13,7 @@ authors:
|
|
13
13
|
autorequire:
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
|
-
date: 2012-08-
|
16
|
+
date: 2012-08-22 00:00:00.000000000 Z
|
17
17
|
dependencies:
|
18
18
|
- !ruby/object:Gem::Dependency
|
19
19
|
name: neo4j
|
@@ -123,27 +123,45 @@ extensions: []
|
|
123
123
|
extra_rdoc_files: []
|
124
124
|
files:
|
125
125
|
- .gitignore
|
126
|
+
- .rbenv-version
|
126
127
|
- .rvmrc
|
127
128
|
- Gemfile
|
128
129
|
- Gemfile.lock
|
129
130
|
- LICENSE
|
130
131
|
- README.md
|
131
132
|
- Rakefile
|
133
|
+
- bin/autospec
|
134
|
+
- bin/coderay
|
135
|
+
- bin/erubis
|
136
|
+
- bin/htmldiff
|
137
|
+
- bin/ldiff
|
138
|
+
- bin/neo4j-jars
|
139
|
+
- bin/neo4j-shell
|
140
|
+
- bin/neo4j-upgrade
|
141
|
+
- bin/pry
|
142
|
+
- bin/rackup
|
143
|
+
- bin/rails
|
144
|
+
- bin/rake
|
145
|
+
- bin/rake2thor
|
146
|
+
- bin/rdebug
|
147
|
+
- bin/ri
|
148
|
+
- bin/rspec
|
149
|
+
- bin/thor
|
150
|
+
- bin/tilt
|
132
151
|
- geoff.gemspec
|
133
152
|
- lib/geoff.rb
|
134
153
|
- lib/geoff/children_dsl.rb
|
135
154
|
- lib/geoff/container.rb
|
136
155
|
- lib/geoff/dsl_exception_handling.rb
|
137
156
|
- lib/geoff/importer.rb
|
138
|
-
- lib/geoff/neo4j_wrapper_dsl.rb
|
139
|
-
- lib/geoff/neo4j_wrapper_validator.rb
|
140
157
|
- lib/geoff/node_dsl.rb
|
141
158
|
- lib/geoff/version.rb
|
142
159
|
- spec/integration/children_dsl_spec.rb
|
160
|
+
- spec/integration/geoff_spec.rb
|
143
161
|
- spec/integration/node_dsl_spec.rb
|
162
|
+
- spec/models/container_spec.rb
|
144
163
|
- spec/models/geoff_spec.rb
|
145
|
-
- spec/
|
146
|
-
- spec/models/neo4j_wrapper_validator_spec.rb
|
164
|
+
- spec/node_dsl_spec.rb
|
147
165
|
- spec/spec_helper.rb
|
148
166
|
- spec/support/geof_matchers.rb
|
149
167
|
homepage: ''
|
@@ -160,9 +178,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
160
178
|
none: false
|
161
179
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
162
180
|
requirements:
|
163
|
-
- - ! '
|
181
|
+
- - ! '>='
|
164
182
|
- !ruby/object:Gem::Version
|
165
|
-
version:
|
183
|
+
version: '0'
|
166
184
|
none: false
|
167
185
|
requirements: []
|
168
186
|
rubyforge_project:
|
@@ -172,10 +190,11 @@ specification_version: 3
|
|
172
190
|
summary: DSL to allow easy generating of data for Neo4j
|
173
191
|
test_files:
|
174
192
|
- spec/integration/children_dsl_spec.rb
|
193
|
+
- spec/integration/geoff_spec.rb
|
175
194
|
- spec/integration/node_dsl_spec.rb
|
195
|
+
- spec/models/container_spec.rb
|
176
196
|
- spec/models/geoff_spec.rb
|
177
|
-
- spec/
|
178
|
-
- spec/models/neo4j_wrapper_validator_spec.rb
|
197
|
+
- spec/node_dsl_spec.rb
|
179
198
|
- spec/spec_helper.rb
|
180
199
|
- spec/support/geof_matchers.rb
|
181
200
|
has_rdoc:
|
@@ -1,50 +0,0 @@
|
|
1
|
-
require 'geoff/children_dsl'
|
2
|
-
|
3
|
-
class Neo4jWrapperDsl
|
4
|
-
def initialize *classes, &block
|
5
|
-
options = classes.last.is_a?(Hash) ? classes.pop : {}
|
6
|
-
|
7
|
-
validate classes
|
8
|
-
|
9
|
-
options.merge!({
|
10
|
-
parent_node_name: 'ROOT',
|
11
|
-
type: nil,
|
12
|
-
container: Container.new
|
13
|
-
})
|
14
|
-
|
15
|
-
@children_dsl = ChildrenDsl.new(options, &block) if block_given?
|
16
|
-
end
|
17
|
-
|
18
|
-
def to_geoff
|
19
|
-
geoff = "#{add_classes}\n"
|
20
|
-
geoff += @children_dsl.to_geoff if @children_dsl
|
21
|
-
geoff.chomp
|
22
|
-
end
|
23
|
-
|
24
|
-
def <=> other
|
25
|
-
to_geoff == other.to_geoff ? 0 : -1
|
26
|
-
end
|
27
|
-
|
28
|
-
def to_s
|
29
|
-
to_geoff
|
30
|
-
end
|
31
|
-
|
32
|
-
private
|
33
|
-
|
34
|
-
def add_classes
|
35
|
-
@classes.map{|c| root_to_class_as_geoff c }.join("\n")
|
36
|
-
end
|
37
|
-
|
38
|
-
def root_to_class_as_geoff c
|
39
|
-
"(ROOT)-[:#{c}]->(#{c})"
|
40
|
-
end
|
41
|
-
|
42
|
-
def validate classes
|
43
|
-
@classes = classes || []
|
44
|
-
|
45
|
-
@classes.each do |c|
|
46
|
-
m = "Class #{c} should include Neo4j::NodeMixin"
|
47
|
-
raise ArgumentError, m unless c.is_a?(Class) and c.included_modules.include? Neo4j::NodeMixin
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
@@ -1,17 +0,0 @@
|
|
1
|
-
class Neo4jWrapperValidator
|
2
|
-
NODE_NAME_REGEX = /^\(([^\)]+)\)/
|
3
|
-
|
4
|
-
def call container, node
|
5
|
-
node_name = node.match(NODE_NAME_REGEX)[1]
|
6
|
-
|
7
|
-
unless class_present? container, node_name
|
8
|
-
raise Geoff::MissingNodeDefinition, node_name
|
9
|
-
end
|
10
|
-
|
11
|
-
true
|
12
|
-
end
|
13
|
-
|
14
|
-
def class_present? container, node_name
|
15
|
-
container.node_list.include? node_name
|
16
|
-
end
|
17
|
-
end
|
@@ -1,86 +0,0 @@
|
|
1
|
-
require File.expand_path('spec/spec_helper')
|
2
|
-
require 'neo4j'
|
3
|
-
require './lib/geoff/neo4j_wrapper_dsl'
|
4
|
-
|
5
|
-
describe Neo4jWrapperDsl do
|
6
|
-
let(:expected_geoff) do
|
7
|
-
strip_whitespace <<-EOS
|
8
|
-
(ROOT)-[:Sandwich]->(Sandwich)
|
9
|
-
(ROOT)-[:Cheese]->(Cheese)
|
10
|
-
(ROOT)-[:Egg]->(Egg)
|
11
|
-
EOS
|
12
|
-
end
|
13
|
-
|
14
|
-
class Sandwich
|
15
|
-
include Neo4j::NodeMixin
|
16
|
-
end
|
17
|
-
|
18
|
-
class Cafe
|
19
|
-
include Neo4j::NodeMixin
|
20
|
-
end
|
21
|
-
|
22
|
-
class Branch
|
23
|
-
include Neo4j::NodeMixin
|
24
|
-
end
|
25
|
-
|
26
|
-
|
27
|
-
class Cheese
|
28
|
-
include Neo4j::NodeMixin
|
29
|
-
end
|
30
|
-
|
31
|
-
class Egg
|
32
|
-
include Neo4j::NodeMixin
|
33
|
-
end
|
34
|
-
|
35
|
-
|
36
|
-
describe "#to_s" do
|
37
|
-
specify do
|
38
|
-
dsl = Neo4jWrapperDsl.new Sandwich, Cheese, Egg
|
39
|
-
dsl.to_s.should == dsl.to_geoff
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
describe "#to_geoff" do
|
44
|
-
it "outputs root node geoff syntax" do
|
45
|
-
dsl = Neo4jWrapperDsl.new(Sandwich, Cheese, Egg)
|
46
|
-
dsl.to_geoff.should == expected_geoff
|
47
|
-
end
|
48
|
-
|
49
|
-
specify do
|
50
|
-
->{Neo4jWrapperDsl.new 2 } .should raise_error ArgumentError
|
51
|
-
->{Neo4jWrapperDsl.new '' } .should raise_error ArgumentError
|
52
|
-
->{Neo4jWrapperDsl.new ['']}.should raise_error ArgumentError
|
53
|
-
->{Neo4jWrapperDsl.new [1]} .should raise_error ArgumentError
|
54
|
-
|
55
|
-
->{Neo4jWrapperDsl.new(Egg)}.should_not raise_error ArgumentError
|
56
|
-
end
|
57
|
-
|
58
|
-
|
59
|
-
context "with a block" do
|
60
|
-
let(:expected) {
|
61
|
-
strip_whitespace <<-EOS
|
62
|
-
(ROOT)-[:Cafe]->(Cafe)
|
63
|
-
(ROOT)-[:Branch]->(Branch)
|
64
|
-
(Starbucks) {"_classname":"Cafe"}
|
65
|
-
(Cafe)-[:all]->(Starbucks)
|
66
|
-
(starbucks_branch) {"_classname":"Branch"}
|
67
|
-
(Branch)-[:all]->(starbucks_branch)
|
68
|
-
(Starbucks)-[:owns]->(starbucks_branch)
|
69
|
-
EOS
|
70
|
-
}
|
71
|
-
|
72
|
-
specify "with parent node is root node, but no relationship,
|
73
|
-
don't create relationship to root node" do
|
74
|
-
Neo4jWrapperDsl.new(Cafe, Branch) do
|
75
|
-
cafe 'Starbucks' do
|
76
|
-
children 'owns' do
|
77
|
-
#create relationship to parent node of type owns (comes from children DSL)
|
78
|
-
branch 'starbucks_branch'
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
end.to_geoff.should == expected
|
83
|
-
end
|
84
|
-
end
|
85
|
-
end
|
86
|
-
end
|
@@ -1,28 +0,0 @@
|
|
1
|
-
require './lib/geoff'
|
2
|
-
require './lib/geoff/neo4j_wrapper_validator'
|
3
|
-
|
4
|
-
describe Neo4jWrapperValidator do
|
5
|
-
let(:validator) { Neo4jWrapperValidator.new }
|
6
|
-
|
7
|
-
{
|
8
|
-
"(Egg)-[:relates]->(1)" => {existing_nodes: %w(Branch Starbucks Cafe), node_name: "Egg", valid: false},
|
9
|
-
"((Branch)-[:relates]->(1)" => {existing_nodes: %w(Branch Cafe Starbucks), node_name: "Branch", valid: false},
|
10
|
-
"(Starbucks)-[:relates]->(1)" => {existing_nodes: %w(Branch Cafe Starbucks), node_name: "Starbucks", valid: true},
|
11
|
-
"((_Branch)-[:relates]->(1)" => {existing_nodes: %w(Branch), node_name: "(_Branch", valid: false},
|
12
|
-
"((Bra nch)-[:relates]->(1)" => {existing_nodes: %w(Branch Cafe), node_name: "(Bra nch", valid: false},
|
13
|
-
"((Branch)-[:relates]->(1)" => {existing_nodes: %w(Branch Cafe), node_name: "(Branch", valid: false},
|
14
|
-
"(Branch)-[:relates]->(1)" => {existing_nodes: [], node_name: "Branch", valid: false}}.each do |input, details|
|
15
|
-
specify do
|
16
|
-
valid = details[:valid]
|
17
|
-
existing_nodes = details[:existing_nodes]
|
18
|
-
node_name = details[:node_name]
|
19
|
-
container = mock 'container', node_list: existing_nodes
|
20
|
-
|
21
|
-
if valid
|
22
|
-
validator.call(container, input).should == true
|
23
|
-
else
|
24
|
-
->{validator.call(container, input)}.should raise_error Geoff::MissingNodeDefinition, node_name
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|