geoff 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- geoff (0.0.3.beta)
4
+ geoff (0.0.6)
5
5
  activesupport (~> 3.2.3)
6
6
  json
7
7
  neo4j
@@ -33,7 +33,7 @@ GEM
33
33
  hike (1.2.1)
34
34
  i18n (0.6.0)
35
35
  journey (1.0.4)
36
- json (1.7.4-java)
36
+ json (1.7.5-java)
37
37
  linecache (0.46)
38
38
  rbx-require-relative (> 0.0.4)
39
39
  method_source (0.8)
@@ -96,7 +96,7 @@ GEM
96
96
  hike (~> 1.2)
97
97
  rack (~> 1.0)
98
98
  tilt (~> 1.1, != 1.3.0)
99
- thor (0.15.4)
99
+ thor (0.16.0)
100
100
  tilt (1.3.3)
101
101
 
102
102
  PLATFORMS
@@ -59,6 +59,7 @@ class ChildrenDsl
59
59
  def rel_geoff node_dsl, properties
60
60
  properties = properties.dup
61
61
  type = properties.delete :type
62
+ properties.delete(:clone)
62
63
 
63
64
  "(#{parent_node_name})-[:#{type}]->(#{node_dsl.node_name})".tap do |r|
64
65
  r << " #{properties.to_json}" if properties.any?
@@ -87,7 +88,11 @@ class ChildrenDsl
87
88
 
88
89
  node_dsls = {}
89
90
  @node_dsls.each do |node_dsl, rel_properties|
90
- node_dsls[node_dsl.clone] = rel_properties.dup
91
+ if rel_properties[:clone] == false
92
+ node_dsls[node_dsl] = rel_properties
93
+ else
94
+ node_dsls[node_dsl.clone] = rel_properties.dup
95
+ end
91
96
  end
92
97
 
93
98
  # sort it out, instance_variable_set is probably not the best way to clone object
@@ -43,7 +43,13 @@ class Container
43
43
 
44
44
  def handle_node_dsl m, *args
45
45
  node_dsl = @node_dsls[m]
46
- rel_properties = args.first
46
+ rel_properties = args.first || {}
47
+
48
+ if rel_properties[:clone]
49
+ node_dsl = node_dsl.clone
50
+ rel_properties.delete(:clone)
51
+ end
52
+
47
53
  @recipient.add_node_dsl node_dsl, rel_properties
48
54
  node_dsl
49
55
  end
data/lib/geoff/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  class Geoff
2
- VERSION = "0.0.6"
2
+ VERSION = "0.0.7"
3
3
  end
@@ -140,7 +140,7 @@ describe Geoff do
140
140
  b.coffee_machine = coffee_machine('illy') do
141
141
  power 2300
142
142
 
143
- children 'includes' do
143
+ children 'connected_to' do
144
144
  grinder 'fine_grinder'
145
145
  end
146
146
  end
@@ -156,7 +156,7 @@ describe Geoff do
156
156
  (CoffeeMachine)-[:all]->(illy_3)
157
157
  (fine_grinder_5) {"_classname":"Grinder"}
158
158
  (Grinder)-[:all]->(fine_grinder_5)
159
- (illy_3)-[:includes]->(fine_grinder_5)
159
+ (illy_3)-[:connected_to]->(fine_grinder_5)
160
160
  (starbucks_luton_branch_1)-[:uses]->(illy_3) {"lease":"3 years"}
161
161
  EOS
162
162
  end
@@ -166,6 +166,53 @@ describe Geoff do
166
166
  geoff.should == expected_geoff
167
167
  end
168
168
  end
169
+ end
170
+
171
+ describe 'cloning subtrees held in b variables' do
172
+ before { stub_node_dsl_object_id }
173
+
174
+ let(:builder) do
175
+ Geoff(Branch) do
176
+ b.grinder = grinder 'fine_grinder'
177
+
178
+ branch 'starbucks_luton_branch' do
179
+ children 'uses' do
180
+ b.illy = coffee_machine('large_illy') do
181
+ power 2300
169
182
 
183
+ children 'connected_to' do
184
+ b.grinder clone: false
185
+ end
186
+ end
187
+
188
+ # this branch uses two identical large illy machines
189
+ b.illy type: 'uses', clone: true
190
+ end
191
+ end
192
+ end
193
+ end
194
+
195
+ let(:expected_geoff) do
196
+ strip_whitespace <<-EOS
197
+ (ROOT)-[:Branch]->(Branch)
198
+ (fine_grinder) {"_classname":"Grinder"}
199
+ (Grinder)-[:all]->(fine_grinder)
200
+ (starbucks_luton_branch) {"_classname":"Branch"}
201
+ (Branch)-[:all]->(starbucks_luton_branch)
202
+ (large_illy) {"_classname":"CoffeeMachine","power":2300}
203
+ (CoffeeMachine)-[:all]->(large_illy)
204
+ (large_illy)-[:connected_to]->(fine_grinder)
205
+ (starbucks_luton_branch)-[:uses]->(large_illy)
206
+ (large_illy) {"_classname":"CoffeeMachine","power":2300}
207
+ (CoffeeMachine)-[:all]->(large_illy)
208
+ (large_illy)-[:connected_to]->(fine_grinder)
209
+ (starbucks_luton_branch)-[:uses]->(large_illy)
210
+ EOS
211
+ end
212
+
213
+ specify do
214
+ geoff = builder.to_geoff
215
+ geoff.should == expected_geoff
216
+ end
170
217
  end
171
218
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: geoff
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.6
5
+ version: 0.0.7
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-31 00:00:00.000000000 Z
16
+ date: 2012-09-03 00:00:00.000000000 Z
17
17
  dependencies:
18
18
  - !ruby/object:Gem::Dependency
19
19
  name: neo4j