xamplr 1.9.15 → 1.9.16
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION.yml +2 -2
- data/lib/xamplr/from-xml.rb +2 -2
- data/lib/xamplr/persister.rb +6 -1
- data/lib/xamplr/persisters/filesystem.rb +4 -2
- data/lib/xamplr/persisters/redis.rb +1 -1
- data/lib/xamplr/persisters/tokyo-cabinet.rb +6 -6
- data/lib/xamplr/tests/redis/redis_spec.rb +164 -159
- data/lib/xamplr/visitors.rb +27 -0
- data/xamplr.gemspec +8 -9
- metadata +46 -65
data/VERSION.yml
CHANGED
data/lib/xamplr/from-xml.rb
CHANGED
@@ -224,7 +224,7 @@ module Xampl
|
|
224
224
|
element = existing_element #TODO -- IS THIS RIGHT????????????????????????
|
225
225
|
end
|
226
226
|
unless element then
|
227
|
-
element = klasses[0].new
|
227
|
+
element = klasses[0].discriminate(@attribute_name, @attribute_namespace, @attribute_value).new
|
228
228
|
requires_caching = @recovering
|
229
229
|
# puts "#{File.basename(__FILE__)} #{__LINE__} WOW, what about recovering????"
|
230
230
|
#TODO -- IS THIS RIGHT????????????????????????
|
@@ -241,7 +241,7 @@ module Xampl
|
|
241
241
|
end
|
242
242
|
|
243
243
|
unless element then
|
244
|
-
element = klasses[0].new
|
244
|
+
element = klasses[0].discriminate(@attribute_name, @attribute_namespace, @attribute_value).new
|
245
245
|
element.note_created(@is_realising)
|
246
246
|
end
|
247
247
|
|
data/lib/xamplr/persister.rb
CHANGED
@@ -135,7 +135,7 @@ module Xampl
|
|
135
135
|
|
136
136
|
def realise(representation, target=nil)
|
137
137
|
# This is a bit brutal, but it works (and, anyway, it *is* the rule is that this is supposed to be UTF-8)
|
138
|
-
representation_fixed = representation.encode('UTF-8', :invalid => :replace, :undef => :replace)
|
138
|
+
representation_fixed = representation.encode('UTF-8', 'UTF-8', :invalid => :replace, :undef => :replace)
|
139
139
|
|
140
140
|
xampl = nil
|
141
141
|
|
@@ -204,6 +204,11 @@ module Xampl
|
|
204
204
|
xampl = read(klass, pid, target)
|
205
205
|
|
206
206
|
# puts " LAZY_LOAD --> #{xampl}"
|
207
|
+
unless xampl
|
208
|
+
puts "*******************************************************************************"
|
209
|
+
puts "***** LAZY_LOAD FAILED:: klass: #{klass} pid: #{pid} target: #{target}"
|
210
|
+
puts "*******************************************************************************"
|
211
|
+
end
|
207
212
|
|
208
213
|
return xampl
|
209
214
|
end
|
@@ -23,7 +23,8 @@ module Xampl
|
|
23
23
|
raise XamplException.new("no_index_so_no_persist [#{xampl.class.name}]") unless xampl.get_the_index or xampl.ignore_when_no_index
|
24
24
|
return unless xampl.get_the_index
|
25
25
|
|
26
|
-
place = File.join(@root_dir, xampl.class.name.split("::"))
|
26
|
+
#place = File.join(@root_dir, xampl.class.name.split("::"))
|
27
|
+
place = File.join(@root_dir, xampl.class.persistence_class.name.split("::"))
|
27
28
|
|
28
29
|
FileUtils.mkdir_p(place) unless File.exist?(place)
|
29
30
|
|
@@ -46,7 +47,8 @@ module Xampl
|
|
46
47
|
end
|
47
48
|
|
48
49
|
def read_representation(klass, pid)
|
49
|
-
place = File.join(@root_dir, klass.name.split("::"), pid)
|
50
|
+
place = File.join(@root_dir, klass.persistence_class.name.split("::"), pid)
|
51
|
+
#place = File.join(@root_dir, klass.name.split("::"), pid)
|
50
52
|
|
51
53
|
return nil unless File.exist?(place)
|
52
54
|
representation = File.read(place)
|
@@ -157,7 +157,7 @@ module Xampl
|
|
157
157
|
|
158
158
|
def key_for_class(klass, index)
|
159
159
|
#NOTE -- the XAMPL::#{ @repo_name }:: is a prefix common to all keys specific to this repository
|
160
|
-
"#{ common_key_prefix }#{ klass.name }[#{ index }]"
|
160
|
+
"#{ common_key_prefix }#{ klass.persistence_class.name }[#{ index }]"
|
161
161
|
end
|
162
162
|
|
163
163
|
def key_for_xampl(xampl)
|
@@ -324,7 +324,7 @@ module Xampl
|
|
324
324
|
def find_mentions_of(xampl)
|
325
325
|
setup_db
|
326
326
|
|
327
|
-
place = File.join(xampl.class.name.split("::"), xampl.get_the_index)
|
327
|
+
place = File.join(xampl.class.persistence_class.name.split("::"), xampl.get_the_index)
|
328
328
|
|
329
329
|
query = TableQuery.new(@tc_db)
|
330
330
|
query.add_condition('xampl-to', :equals, place)
|
@@ -435,7 +435,7 @@ module Xampl
|
|
435
435
|
|
436
436
|
def how_indexed(xampl)
|
437
437
|
raise XamplException.new(:no_index_so_no_persist) unless xampl.get_the_index
|
438
|
-
place = File.join(xampl.class.name.split("::"), xampl.get_the_index)
|
438
|
+
place = File.join(xampl.class.persistence_class.name.split("::"), xampl.get_the_index)
|
439
439
|
|
440
440
|
setup_db
|
441
441
|
|
@@ -497,7 +497,7 @@ module Xampl
|
|
497
497
|
# puts "#{File.basename(__FILE__)}:#{__LINE__} [#{ __method__ }] EXPUNGING #{ xampl }/#{ expunging }"
|
498
498
|
# end
|
499
499
|
|
500
|
-
place_dir = xampl.class.name.split("::")
|
500
|
+
place_dir = xampl.class.persistence_class.name.split("::")
|
501
501
|
place = File.join( place_dir, xampl.get_the_index)
|
502
502
|
place_dir = File.join( @files_dir, place_dir )
|
503
503
|
mentions = Set.new
|
@@ -533,7 +533,7 @@ module Xampl
|
|
533
533
|
if Xampl.raw_persister_options[:mentions] then
|
534
534
|
# TODO -- This can be slow
|
535
535
|
mentions.each do | mention |
|
536
|
-
mention_place = File.join(mention.class.name.split("::"), mention.get_the_index)
|
536
|
+
mention_place = File.join(mention.class.persistence_class.name.split("::"), mention.get_the_index)
|
537
537
|
#TODO -- will repeadedly changing a persisted xampl object fragment the TC db?
|
538
538
|
|
539
539
|
pk = @tc_db.genuid
|
@@ -649,7 +649,7 @@ module Xampl
|
|
649
649
|
setup_db
|
650
650
|
end
|
651
651
|
|
652
|
-
place = File.join(klass.name.split("::"), pid)
|
652
|
+
place = File.join(klass.persistence_class.name.split("::"), pid)
|
653
653
|
|
654
654
|
meta = @tc_db[place]
|
655
655
|
representation = meta['xampl'] if meta
|
@@ -662,7 +662,7 @@ module Xampl
|
|
662
662
|
|
663
663
|
unless representation then
|
664
664
|
# try the filesystem if it is not in the TC repository
|
665
|
-
place = File.join(@root_dir, klass.name.split("::"), pid)
|
665
|
+
place = File.join(@root_dir, klass.persistence_class.name.split("::"), pid)
|
666
666
|
representation = File.read(place) if File.exist?(place)
|
667
667
|
$FS_COUNT += 1 if representation
|
668
668
|
# puts "#{File.basename(__FILE__)}:#{__LINE__} FS: #{ klass }/#{ pid } (FS: #{ $FS_COUNT}, TC: #{ $TC_COUNT }, NF: #{ $NF_COUNT }" if representation
|
@@ -5,9 +5,9 @@ module Xampl
|
|
5
5
|
describe 'redis creation and connections' do
|
6
6
|
before :each do
|
7
7
|
Xampl.drop_all_persisters
|
8
|
-
Xampl.set_default_persister_properties(:testing
|
9
|
-
:allow_connections
|
10
|
-
:connect_to_known
|
8
|
+
Xampl.set_default_persister_properties(:testing => true,
|
9
|
+
:allow_connections => false,
|
10
|
+
:connect_to_known => false,
|
11
11
|
:connect_to_unknown => false)
|
12
12
|
end
|
13
13
|
after :each do
|
@@ -15,7 +15,7 @@ module Xampl
|
|
15
15
|
|
16
16
|
it 'will create a named instance of the redis persister' do
|
17
17
|
repo_name = XamplTestRedis.scratch_name('redis')
|
18
|
-
redis
|
18
|
+
redis = Xampl.create_named_persister(repo_name, :redis)
|
19
19
|
|
20
20
|
redis.should be_an_instance_of(RedisPersister)
|
21
21
|
redis.repo_name.should == repo_name
|
@@ -38,7 +38,7 @@ module Xampl
|
|
38
38
|
end
|
39
39
|
|
40
40
|
it 'will generate useful keys' do
|
41
|
-
redis
|
41
|
+
redis = Xampl.create_named_persister(XamplTestRedis.scratch_name('redis'), :redis)
|
42
42
|
|
43
43
|
thing1 = XamplTestRedis::DroolingIdiotPersistedObject.new(XamplTestRedis.scratch_name('xo'))
|
44
44
|
thing2 = XamplTestRedis::DroolingIdiotPersistedObject.new(XamplTestRedis.scratch_name('xo'))
|
@@ -54,7 +54,7 @@ module Xampl
|
|
54
54
|
redis1 = Xampl.create_named_persister(XamplTestRedis.scratch_name('redis'), :redis)
|
55
55
|
redis2 = Xampl.create_named_persister(XamplTestRedis.scratch_name('redis'), :redis)
|
56
56
|
|
57
|
-
thing
|
57
|
+
thing = XamplTestRedis::DroolingIdiotPersistedObject.new('test')
|
58
58
|
|
59
59
|
redis1.key_for_class(thing.class, thing.get_the_index).should_not == redis2.key_for_class(thing.class, thing.get_the_index).should
|
60
60
|
redis1.key_for_xampl(thing).should_not == redis2.key_for_xampl(thing).should_not
|
@@ -74,7 +74,7 @@ module Xampl
|
|
74
74
|
end
|
75
75
|
|
76
76
|
it 'will moan if two different objects are cached under the same key' do
|
77
|
-
redis
|
77
|
+
redis = Xampl.create_named_persister(XamplTestRedis.scratch_name('redis'), :redis)
|
78
78
|
|
79
79
|
thing1 = XamplTestRedis::DroolingIdiotPersistedObject.new('test')
|
80
80
|
thing2 = XamplTestRedis::DroolingIdiotPersistedObject.new('test')
|
@@ -90,10 +90,10 @@ module Xampl
|
|
90
90
|
end
|
91
91
|
|
92
92
|
it 'will store if two different objects are cached under the same key if the first is removed from the cache first' do
|
93
|
-
redis
|
93
|
+
redis = Xampl.create_named_persister(XamplTestRedis.scratch_name('redis'), :redis)
|
94
94
|
|
95
|
-
thing1
|
96
|
-
thing2
|
95
|
+
thing1 = XamplTestRedis::DroolingIdiotPersistedObject.new('test')
|
96
|
+
thing2 = XamplTestRedis::DroolingIdiotPersistedObject.new('test')
|
97
97
|
|
98
98
|
redis.perm_cache(thing1)
|
99
99
|
uncached = redis.perm_uncache(thing1)
|
@@ -120,7 +120,7 @@ module Xampl
|
|
120
120
|
end
|
121
121
|
|
122
122
|
it 'will have weak cache references' do
|
123
|
-
redis
|
123
|
+
redis = Xampl.create_named_persister(XamplTestRedis.scratch_name('redis'), :redis)
|
124
124
|
|
125
125
|
thing_referenced = XamplTestRedis::DroolingIdiotPersistedObject.new('referenced')
|
126
126
|
|
@@ -142,12 +142,12 @@ module Xampl
|
|
142
142
|
end
|
143
143
|
|
144
144
|
it 'will establish a redis connection to an unknown redis database' do
|
145
|
-
redis
|
146
|
-
|
147
|
-
|
148
|
-
|
145
|
+
redis = Xampl.create_named_persister(XamplTestRedis.scratch_name('redis'), :redis,
|
146
|
+
:allow_connections => true,
|
147
|
+
:connect_to_known => false,
|
148
|
+
:connect_to_unknown => true)
|
149
149
|
|
150
|
-
client
|
150
|
+
client = redis.client
|
151
151
|
client.should be_an_instance_of(::Redis)
|
152
152
|
|
153
153
|
repo_properties = redis.repo_properties
|
@@ -157,13 +157,13 @@ module Xampl
|
|
157
157
|
end
|
158
158
|
|
159
159
|
it 'will establish a redis connection to an known redis database' do
|
160
|
-
repo_name
|
161
|
-
redis1
|
162
|
-
|
163
|
-
|
164
|
-
|
160
|
+
repo_name = XamplTestRedis.scratch_name('redis')
|
161
|
+
redis1 = Xampl.create_named_persister(repo_name, :redis,
|
162
|
+
:allow_connections => true,
|
163
|
+
:connect_to_known => false,
|
164
|
+
:connect_to_unknown => true)
|
165
165
|
|
166
|
-
client
|
166
|
+
client = redis1.client
|
167
167
|
client.should be_an_instance_of(::Redis)
|
168
168
|
|
169
169
|
repo_properties = redis1.repo_properties
|
@@ -173,12 +173,12 @@ module Xampl
|
|
173
173
|
|
174
174
|
Xampl.drop_persister(repo_name)
|
175
175
|
|
176
|
-
redis2
|
177
|
-
|
178
|
-
|
179
|
-
|
176
|
+
redis2 = Xampl.create_named_persister(repo_name, :redis,
|
177
|
+
:allow_connections => true,
|
178
|
+
:connect_to_known => true,
|
179
|
+
:connect_to_unknown => false)
|
180
180
|
|
181
|
-
client
|
181
|
+
client = redis2.client
|
182
182
|
client.should be_an_instance_of(::Redis)
|
183
183
|
end
|
184
184
|
|
@@ -186,42 +186,42 @@ module Xampl
|
|
186
186
|
repo_name = XamplTestRedis.scratch_name('redis')
|
187
187
|
lambda do
|
188
188
|
Xampl.create_named_persister(repo_name, :redis,
|
189
|
-
:allow_connections
|
190
|
-
:connect_to_known
|
189
|
+
:allow_connections => true,
|
190
|
+
:connect_to_known => true,
|
191
191
|
:connect_to_unknown => false)
|
192
192
|
end.should raise_exception(IncompatiblePersisterConfiguration)
|
193
193
|
end
|
194
194
|
|
195
195
|
it 'will prevent connections to existing repositories' do
|
196
196
|
repo_name = XamplTestRedis.scratch_name('redis')
|
197
|
-
redis1
|
198
|
-
|
199
|
-
|
200
|
-
|
197
|
+
redis1 = Xampl.create_named_persister(repo_name, :redis,
|
198
|
+
:allow_connections => true,
|
199
|
+
:connect_to_known => false,
|
200
|
+
:connect_to_unknown => true)
|
201
201
|
|
202
|
-
client
|
202
|
+
client = redis1.client
|
203
203
|
client.should be_an_instance_of(::Redis)
|
204
204
|
|
205
205
|
Xampl.drop_persister(repo_name)
|
206
206
|
|
207
207
|
lambda do
|
208
208
|
Xampl.create_named_persister(repo_name, :redis,
|
209
|
-
:allow_connections
|
210
|
-
:connect_to_known
|
209
|
+
:allow_connections => true,
|
210
|
+
:connect_to_known => false,
|
211
211
|
:connect_to_unknown => true)
|
212
212
|
end.should raise_exception(IncompatiblePersisterConfiguration)
|
213
213
|
end
|
214
214
|
|
215
215
|
it "will connect to two different repositories in the same redis db" do
|
216
|
-
redis1
|
217
|
-
|
218
|
-
|
219
|
-
|
216
|
+
redis1 = Xampl.create_named_persister(XamplTestRedis.scratch_name('redis'), :redis,
|
217
|
+
:allow_connections => true,
|
218
|
+
:connect_to_known => false,
|
219
|
+
:connect_to_unknown => true)
|
220
220
|
redis1.should_not be_nil
|
221
|
-
redis2
|
222
|
-
|
223
|
-
|
224
|
-
|
221
|
+
redis2 = Xampl.create_named_persister(XamplTestRedis.scratch_name('redis'), :redis,
|
222
|
+
:allow_connections => true,
|
223
|
+
:connect_to_known => false,
|
224
|
+
:connect_to_unknown => true)
|
225
225
|
redis2.should_not be_nil
|
226
226
|
redis2.should_not == redis1
|
227
227
|
|
@@ -231,32 +231,32 @@ module Xampl
|
|
231
231
|
|
232
232
|
it "will only create one persister wiith a given name" do
|
233
233
|
repo_name = XamplTestRedis.scratch_name('redis')
|
234
|
-
redis1
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
redis2
|
239
|
-
|
240
|
-
|
241
|
-
|
234
|
+
redis1 = Xampl.create_named_persister(repo_name, :redis,
|
235
|
+
:allow_connections => true,
|
236
|
+
:connect_to_known => true,
|
237
|
+
:connect_to_unknown => true)
|
238
|
+
redis2 = Xampl.create_named_persister(repo_name, :redis,
|
239
|
+
:allow_connections => true,
|
240
|
+
:connect_to_known => true,
|
241
|
+
:connect_to_unknown => true)
|
242
242
|
|
243
243
|
redis1.should == redis2
|
244
244
|
end
|
245
245
|
|
246
246
|
it 'will allow clobbering an entire redis database when clobbering is explicitly enabled' do
|
247
|
-
repo_name1
|
248
|
-
redis1
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
repo_name2
|
254
|
-
redis2
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
known_repos
|
247
|
+
repo_name1 = XamplTestRedis.scratch_name('redis')
|
248
|
+
redis1 = Xampl.create_named_persister(repo_name1, :redis,
|
249
|
+
:clobbering_allowed => true,
|
250
|
+
:allow_connections => true,
|
251
|
+
:connect_to_known => true,
|
252
|
+
:connect_to_unknown => true)
|
253
|
+
repo_name2 = XamplTestRedis.scratch_name('redis')
|
254
|
+
redis2 = Xampl.create_named_persister(repo_name2, :redis,
|
255
|
+
:allow_connections => true,
|
256
|
+
:connect_to_known => true,
|
257
|
+
:connect_to_unknown => true)
|
258
|
+
|
259
|
+
known_repos = redis2.known_repos
|
260
260
|
known_repos.should include(repo_name1, repo_name2)
|
261
261
|
|
262
262
|
redis1_repo_properties_key = redis1.repo_properties_key
|
@@ -264,12 +264,12 @@ module Xampl
|
|
264
264
|
redis2.client.exists(redis1_repo_properties_key).should be_true
|
265
265
|
|
266
266
|
# add some non-standard keys for this
|
267
|
-
prefix
|
268
|
-
extra1
|
267
|
+
prefix = redis1.common_key_prefix
|
268
|
+
extra1 = "#{ prefix }one"
|
269
269
|
redis1.client.set(extra1, "one")
|
270
|
-
extra2
|
270
|
+
extra2 = "#{ prefix }two"
|
271
271
|
redis1.client.set(extra2, "two")
|
272
|
-
extra3
|
272
|
+
extra3 = "#{ prefix }three"
|
273
273
|
redis1.client.set(extra3, "three")
|
274
274
|
|
275
275
|
redis2.client.get(extra1).should == "one"
|
@@ -278,7 +278,7 @@ module Xampl
|
|
278
278
|
|
279
279
|
redis1.clobber
|
280
280
|
|
281
|
-
known_repos
|
281
|
+
known_repos = redis2.known_repos
|
282
282
|
known_repos.should_not include(repo_name1)
|
283
283
|
known_repos.should include(repo_name2)
|
284
284
|
|
@@ -291,10 +291,10 @@ module Xampl
|
|
291
291
|
|
292
292
|
it 'will *not* allow clobbering an entire redis database when clobbering is *not* explicitly enabled' do
|
293
293
|
repo_name1 = XamplTestRedis.scratch_name('redis')
|
294
|
-
redis1
|
295
|
-
|
296
|
-
|
297
|
-
|
294
|
+
redis1 = Xampl.create_named_persister(repo_name1, :redis,
|
295
|
+
:allow_connections => true,
|
296
|
+
:connect_to_known => true,
|
297
|
+
:connect_to_unknown => true)
|
298
298
|
|
299
299
|
lambda do
|
300
300
|
redis1.clobber
|
@@ -303,10 +303,10 @@ module Xampl
|
|
303
303
|
|
304
304
|
|
305
305
|
it 'will re-establish a redis connection' do
|
306
|
-
redis
|
307
|
-
|
308
|
-
|
309
|
-
|
306
|
+
redis = Xampl.create_named_persister(XamplTestRedis.scratch_name('redis'), :redis,
|
307
|
+
:allow_connections => true,
|
308
|
+
:connect_to_known => true,
|
309
|
+
:connect_to_unknown => true)
|
310
310
|
|
311
311
|
redis_client = redis.client
|
312
312
|
redis_client.client.should be_connected
|
@@ -326,9 +326,9 @@ module Xampl
|
|
326
326
|
describe 'redis reading and writing xampl objects' do
|
327
327
|
before :each do
|
328
328
|
Xampl.drop_all_persisters
|
329
|
-
Xampl.set_default_persister_properties(:testing
|
330
|
-
:allow_connections
|
331
|
-
:connect_to_known
|
329
|
+
Xampl.set_default_persister_properties(:testing => true,
|
330
|
+
:allow_connections => true,
|
331
|
+
:connect_to_known => true,
|
332
332
|
:connect_to_unknown => true)
|
333
333
|
end
|
334
334
|
after :each do
|
@@ -336,14 +336,14 @@ module Xampl
|
|
336
336
|
|
337
337
|
|
338
338
|
it "will write an xampl object" do
|
339
|
-
repo_name
|
340
|
-
redis
|
339
|
+
repo_name = XamplTestRedis.scratch_name('redis')
|
340
|
+
redis = Xampl.create_named_persister(repo_name, :redis)
|
341
341
|
|
342
|
-
redis_client
|
342
|
+
redis_client = redis.client
|
343
343
|
redis_client.client.should be_connected
|
344
344
|
|
345
|
-
author_pid
|
346
|
-
key
|
345
|
+
author_pid = 'anonymous'
|
346
|
+
key = redis.key_for_class(RedisTest::Author, author_pid)
|
347
347
|
|
348
348
|
redis.in_any_cache?(RedisTest::Author, author_pid).should be_false
|
349
349
|
|
@@ -352,7 +352,7 @@ module Xampl
|
|
352
352
|
|
353
353
|
redis.in_any_cache?(RedisTest::Author, author_pid).should be_false
|
354
354
|
|
355
|
-
author
|
355
|
+
author = nil
|
356
356
|
Xampl.transaction(repo_name) do
|
357
357
|
author = RedisTest::Author.new(author_pid)
|
358
358
|
|
@@ -361,8 +361,8 @@ module Xampl
|
|
361
361
|
redis.in_cache?(RedisTest::Author, author_pid).should be_false
|
362
362
|
end
|
363
363
|
|
364
|
-
mentions
|
365
|
-
xml
|
364
|
+
mentions = []
|
365
|
+
xml = redis.represent(author, mentions)
|
366
366
|
|
367
367
|
current_value = redis_client.get(key)
|
368
368
|
current_value.should == xml
|
@@ -375,7 +375,7 @@ module Xampl
|
|
375
375
|
|
376
376
|
redis.in_cache?(RedisTest::Author, author_pid).should be_true
|
377
377
|
|
378
|
-
author
|
378
|
+
author = nil
|
379
379
|
|
380
380
|
GC.start
|
381
381
|
|
@@ -386,20 +386,20 @@ module Xampl
|
|
386
386
|
end
|
387
387
|
|
388
388
|
it "will write a changed xampl object" do
|
389
|
-
repo_name
|
390
|
-
redis
|
391
|
-
redis_client
|
389
|
+
repo_name = XamplTestRedis.scratch_name('redis')
|
390
|
+
redis = Xampl.create_named_persister(repo_name, :redis)
|
391
|
+
redis_client = redis.client
|
392
392
|
|
393
|
-
author_pid
|
394
|
-
key
|
393
|
+
author_pid = 'anonymous'
|
394
|
+
key = redis.key_for_class(RedisTest::Author, author_pid)
|
395
395
|
|
396
|
-
author
|
396
|
+
author = nil
|
397
397
|
Xampl.transaction(repo_name) do
|
398
398
|
author = RedisTest::Author.new(author_pid)
|
399
399
|
end
|
400
400
|
|
401
|
-
mentions
|
402
|
-
xml1
|
401
|
+
mentions = []
|
402
|
+
xml1 = redis.represent(author, mentions)
|
403
403
|
|
404
404
|
current_value = redis_client.get(key)
|
405
405
|
current_value.should == xml1
|
@@ -410,8 +410,8 @@ module Xampl
|
|
410
410
|
end
|
411
411
|
author.should_not be_dirty
|
412
412
|
|
413
|
-
mentions
|
414
|
-
xml2
|
413
|
+
mentions = []
|
414
|
+
xml2 = redis.represent(author, mentions)
|
415
415
|
|
416
416
|
xml2.should_not == xml1
|
417
417
|
|
@@ -420,16 +420,16 @@ module Xampl
|
|
420
420
|
end
|
421
421
|
|
422
422
|
it "will read a xampl object with different redis instances" do
|
423
|
-
repo_name
|
423
|
+
repo_name = XamplTestRedis.scratch_name('redis')
|
424
424
|
Xampl.create_named_persister(repo_name, :redis)
|
425
425
|
|
426
|
-
author_pid
|
426
|
+
author_pid = 'anonymous'
|
427
427
|
|
428
|
-
author_info
|
428
|
+
author_info = XamplTestRedis.scratch_name('author-info')
|
429
429
|
author_object_id_original = nil
|
430
430
|
Xampl.transaction(repo_name) do
|
431
|
-
author
|
432
|
-
author.info
|
431
|
+
author = RedisTest::Author.new(author_pid)
|
432
|
+
author.info = author_info
|
433
433
|
author_object_id_original = author.object_id
|
434
434
|
end
|
435
435
|
|
@@ -440,7 +440,7 @@ module Xampl
|
|
440
440
|
|
441
441
|
Xampl.create_named_persister(repo_name, :redis)
|
442
442
|
|
443
|
-
author
|
443
|
+
author = nil
|
444
444
|
Xampl.transaction(repo_name) do
|
445
445
|
author = RedisTest::Author[author_pid]
|
446
446
|
end
|
@@ -451,22 +451,22 @@ module Xampl
|
|
451
451
|
end
|
452
452
|
|
453
453
|
it "will read a xampl object from cache of same redis instance" do
|
454
|
-
repo_name
|
454
|
+
repo_name = XamplTestRedis.scratch_name('redis')
|
455
455
|
Xampl.create_named_persister(repo_name, :redis)
|
456
456
|
|
457
|
-
author_pid
|
457
|
+
author_pid = 'anonymous'
|
458
458
|
|
459
|
-
author_info
|
459
|
+
author_info = XamplTestRedis.scratch_name('author-info')
|
460
460
|
author_object_id_original = nil
|
461
461
|
Xampl.transaction(repo_name) do
|
462
|
-
author
|
463
|
-
author.info
|
462
|
+
author = RedisTest::Author.new(author_pid)
|
463
|
+
author.info = author_info
|
464
464
|
author_object_id_original = author.object_id
|
465
465
|
end
|
466
466
|
|
467
467
|
Xampl.create_named_persister(repo_name, :redis)
|
468
468
|
|
469
|
-
author
|
469
|
+
author = nil
|
470
470
|
Xampl.transaction(repo_name) do
|
471
471
|
author = RedisTest::Author[author_pid]
|
472
472
|
end
|
@@ -477,16 +477,16 @@ module Xampl
|
|
477
477
|
end
|
478
478
|
|
479
479
|
it "will read a xampl object flushed from the cache cache of same redis instance" do
|
480
|
-
repo_name
|
480
|
+
repo_name = XamplTestRedis.scratch_name('redis')
|
481
481
|
Xampl.create_named_persister(repo_name, :redis)
|
482
482
|
|
483
|
-
author_pid
|
483
|
+
author_pid = 'anonymous'
|
484
484
|
|
485
|
-
author_info
|
485
|
+
author_info = XamplTestRedis.scratch_name('author-info')
|
486
486
|
author_object_id_original = nil
|
487
487
|
Xampl.transaction(repo_name) do
|
488
|
-
author
|
489
|
-
author.info
|
488
|
+
author = RedisTest::Author.new(author_pid)
|
489
|
+
author.info = author_info
|
490
490
|
author_object_id_original = author.object_id
|
491
491
|
end
|
492
492
|
|
@@ -514,14 +514,14 @@ module Xampl
|
|
514
514
|
end
|
515
515
|
|
516
516
|
it "will rollback a newly created xampl object" do
|
517
|
-
repo_name
|
518
|
-
redis
|
517
|
+
repo_name = XamplTestRedis.scratch_name('redis')
|
518
|
+
redis = Xampl.create_named_persister(repo_name, :redis)
|
519
519
|
redis_client = redis.client
|
520
520
|
|
521
|
-
author_pid
|
522
|
-
key
|
521
|
+
author_pid = 'anonymous'
|
522
|
+
key = redis.key_for_class(RedisTest::Author, author_pid)
|
523
523
|
|
524
|
-
author
|
524
|
+
author = nil
|
525
525
|
lambda do
|
526
526
|
Xampl.transaction(repo_name) do
|
527
527
|
author = RedisTest::Author.new(author_pid)
|
@@ -541,14 +541,14 @@ module Xampl
|
|
541
541
|
end
|
542
542
|
|
543
543
|
it "will NOT rollback a newly created xampl object when throwing" do
|
544
|
-
repo_name
|
545
|
-
redis
|
544
|
+
repo_name = XamplTestRedis.scratch_name('redis')
|
545
|
+
redis = Xampl.create_named_persister(repo_name, :redis)
|
546
546
|
redis_client = redis.client
|
547
547
|
|
548
|
-
author_pid
|
549
|
-
key
|
548
|
+
author_pid = 'anonymous'
|
549
|
+
key = redis.key_for_class(RedisTest::Author, author_pid)
|
550
550
|
|
551
|
-
author
|
551
|
+
author = nil
|
552
552
|
|
553
553
|
lambda do
|
554
554
|
Xampl.transaction(repo_name) do
|
@@ -569,21 +569,21 @@ module Xampl
|
|
569
569
|
end
|
570
570
|
|
571
571
|
it "will rollback a changed xampl object" do
|
572
|
-
repo_name
|
573
|
-
redis
|
574
|
-
redis_client
|
572
|
+
repo_name = XamplTestRedis.scratch_name('redis')
|
573
|
+
redis = Xampl.create_named_persister(repo_name, :redis)
|
574
|
+
redis_client = redis.client
|
575
575
|
|
576
|
-
author_pid
|
577
|
-
key
|
576
|
+
author_pid = 'anonymous'
|
577
|
+
key = redis.key_for_class(RedisTest::Author, author_pid)
|
578
578
|
|
579
|
-
author
|
579
|
+
author = nil
|
580
580
|
Xampl.transaction(repo_name) do
|
581
581
|
author = RedisTest::Author.new(author_pid)
|
582
582
|
end
|
583
583
|
author.info.should be_nil
|
584
584
|
|
585
|
-
mentions
|
586
|
-
xml1
|
585
|
+
mentions = []
|
586
|
+
xml1 = redis.represent(author, mentions)
|
587
587
|
|
588
588
|
current_value = redis_client.get(key)
|
589
589
|
current_value.should == xml1
|
@@ -603,8 +603,8 @@ module Xampl
|
|
603
603
|
author.should_not be_invalid # set by the invalidated hook (see author.rb in this directory)
|
604
604
|
author.should_not be_invalidated # a built-in xampl method based on kind_of?(InvalidXampl)
|
605
605
|
|
606
|
-
mentions
|
607
|
-
xml2
|
606
|
+
mentions = []
|
607
|
+
xml2 = redis.represent(author, mentions)
|
608
608
|
|
609
609
|
xml2.should == xml1
|
610
610
|
|
@@ -613,21 +613,21 @@ module Xampl
|
|
613
613
|
end
|
614
614
|
|
615
615
|
it "will NOT rollback a changed xampl object after throwing" do
|
616
|
-
repo_name
|
617
|
-
redis
|
618
|
-
redis_client
|
616
|
+
repo_name = XamplTestRedis.scratch_name('redis')
|
617
|
+
redis = Xampl.create_named_persister(repo_name, :redis)
|
618
|
+
redis_client = redis.client
|
619
619
|
|
620
|
-
author_pid
|
621
|
-
key
|
620
|
+
author_pid = 'anonymous'
|
621
|
+
key = redis.key_for_class(RedisTest::Author, author_pid)
|
622
622
|
|
623
|
-
author
|
623
|
+
author = nil
|
624
624
|
Xampl.transaction(repo_name) do
|
625
625
|
author = RedisTest::Author.new(author_pid)
|
626
626
|
end
|
627
627
|
author.info.should be_nil
|
628
628
|
|
629
|
-
mentions
|
630
|
-
xml1
|
629
|
+
mentions = []
|
630
|
+
xml1 = redis.represent(author, mentions)
|
631
631
|
|
632
632
|
current_value = redis_client.get(key)
|
633
633
|
current_value.should == xml1
|
@@ -647,8 +647,8 @@ module Xampl
|
|
647
647
|
author.should_not be_invalid # set by the invalidated hook (see author.rb in this directory)
|
648
648
|
author.should_not be_invalidated # a built-in xampl method based on kind_of?(InvalidXampl)
|
649
649
|
|
650
|
-
mentions
|
651
|
-
xml2
|
650
|
+
mentions = []
|
651
|
+
xml2 = redis.represent(author, mentions)
|
652
652
|
|
653
653
|
xml2.should_not == xml1
|
654
654
|
|
@@ -657,13 +657,13 @@ module Xampl
|
|
657
657
|
end
|
658
658
|
|
659
659
|
it "will create an object in a nested transaction" do
|
660
|
-
author_pid
|
660
|
+
author_pid = 'anonymous'
|
661
661
|
|
662
|
-
outer_repo_name
|
663
|
-
outer_redis
|
662
|
+
outer_repo_name = XamplTestRedis.scratch_name('redis')
|
663
|
+
outer_redis = Xampl.create_named_persister(outer_repo_name, :redis)
|
664
664
|
|
665
|
-
inner_repo_name
|
666
|
-
inner_redis
|
665
|
+
inner_repo_name = XamplTestRedis.scratch_name('redis')
|
666
|
+
inner_redis = Xampl.create_named_persister(inner_repo_name, :redis)
|
667
667
|
|
668
668
|
outer_redis_client = outer_redis.client
|
669
669
|
inner_redis_client = inner_redis.client
|
@@ -671,16 +671,16 @@ module Xampl
|
|
671
671
|
outer_redis_client.client.should be_connected
|
672
672
|
inner_redis_client.client.should be_connected
|
673
673
|
|
674
|
-
outer_key
|
675
|
-
inner_key
|
674
|
+
outer_key = outer_redis.key_for_class(RedisTest::Author, author_pid)
|
675
|
+
inner_key = inner_redis.key_for_class(RedisTest::Author, author_pid)
|
676
676
|
|
677
|
-
outer_value
|
677
|
+
outer_value = outer_redis_client.get(outer_key)
|
678
678
|
outer_value.should be_nil
|
679
679
|
|
680
|
-
inner_value
|
680
|
+
inner_value = inner_redis_client.get(inner_key)
|
681
681
|
inner_value.should be_nil
|
682
682
|
|
683
|
-
author
|
683
|
+
author = nil
|
684
684
|
|
685
685
|
Xampl.transaction(outer_repo_name) do
|
686
686
|
Xampl.transaction(inner_repo_name) do
|
@@ -693,10 +693,10 @@ module Xampl
|
|
693
693
|
#TODO -- throw in inner
|
694
694
|
#TODO -- throw in outer
|
695
695
|
|
696
|
-
outer_value
|
696
|
+
outer_value = outer_redis_client.get(outer_key)
|
697
697
|
outer_value.should be_nil
|
698
698
|
|
699
|
-
inner_value
|
699
|
+
inner_value = inner_redis_client.get(inner_key)
|
700
700
|
inner_value.should == author.to_xml
|
701
701
|
|
702
702
|
author.should_not be_nil
|
@@ -708,6 +708,11 @@ module Xampl
|
|
708
708
|
end.should_not raise_exception(Xampl::XamplIsInvalid)
|
709
709
|
end
|
710
710
|
|
711
|
+
# def blah
|
712
|
+
# blahblah(:a => 1, :b =>2)
|
713
|
+
# blahblah(a: 1, b: 2)
|
714
|
+
# end
|
715
|
+
|
711
716
|
# explicit return cannot be tested because rspec is doing something
|
712
717
|
|
713
718
|
# it "will zzz" do
|
data/lib/xamplr/visitors.rb
CHANGED
@@ -1,6 +1,29 @@
|
|
1
1
|
#encoding: utf-8
|
2
2
|
module Xampl
|
3
3
|
|
4
|
+
class RemoveWhitespaceContentVisitor < Visitor
|
5
|
+
#
|
6
|
+
# This can be useful for cleaning up DSLs embedded in XML/xampl
|
7
|
+
#
|
8
|
+
def initialize
|
9
|
+
super
|
10
|
+
end
|
11
|
+
|
12
|
+
def after_visit(xampl)
|
13
|
+
xampl.after_visit_by_element_kind(self) if xampl.respond_to? "after_visit_by_element_kind"
|
14
|
+
end
|
15
|
+
|
16
|
+
def after_visit_simple_content(xampl)
|
17
|
+
text = xampl.content
|
18
|
+
xampl.content = nil if text && text.match(/\S/).nil?
|
19
|
+
end
|
20
|
+
|
21
|
+
def after_visit_data_content(xampl)
|
22
|
+
text = xampl.content
|
23
|
+
xampl.content = nil if text && text.match(/\S/).nil?
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
4
27
|
class CountingVisitor < Visitor
|
5
28
|
attr_accessor :count
|
6
29
|
|
@@ -557,6 +580,10 @@ module Xampl
|
|
557
580
|
end
|
558
581
|
|
559
582
|
module XamplObject
|
583
|
+
def remove_ws_content()
|
584
|
+
RemoveWhitespaceContentVisitor.new.start(self)
|
585
|
+
end
|
586
|
+
|
560
587
|
def pp_xml(out="", skip=[])
|
561
588
|
PrettyXML.new(out, skip).start(self).done
|
562
589
|
end
|
data/xamplr.gemspec
CHANGED
@@ -4,14 +4,14 @@
|
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
|
-
s.name =
|
8
|
-
s.version = "1.9.
|
7
|
+
s.name = "xamplr"
|
8
|
+
s.version = "1.9.16"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Bob Hutchison"]
|
12
|
-
s.date =
|
13
|
-
s.description =
|
14
|
-
s.email =
|
12
|
+
s.date = "2012-06-08"
|
13
|
+
s.description = "xamplr is the ruby version of xampl."
|
14
|
+
s.email = "hutch@recursive.ca"
|
15
15
|
s.extra_rdoc_files = [
|
16
16
|
"LICENSE",
|
17
17
|
"README.md"
|
@@ -127,14 +127,13 @@ Gem::Specification.new do |s|
|
|
127
127
|
"regression/tightly-nested-mutual-mentions/xml/stuff.xml",
|
128
128
|
"xamplr.gemspec"
|
129
129
|
]
|
130
|
-
s.homepage =
|
130
|
+
s.homepage = "http://github.com/hutch/xamplr"
|
131
131
|
s.rdoc_options = ["--charset=UTF-8"]
|
132
132
|
s.require_paths = ["lib"]
|
133
|
-
s.rubygems_version =
|
134
|
-
s.summary =
|
133
|
+
s.rubygems_version = "1.8.24"
|
134
|
+
s.summary = "xamplr is the ruby version of xampl"
|
135
135
|
|
136
136
|
if s.respond_to? :specification_version then
|
137
|
-
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
138
137
|
s.specification_version = 3
|
139
138
|
|
140
139
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
metadata
CHANGED
@@ -1,65 +1,56 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: xamplr
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
prerelease:
|
6
|
-
segments:
|
7
|
-
- 1
|
8
|
-
- 9
|
9
|
-
- 15
|
10
|
-
version: 1.9.15
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.9.16
|
5
|
+
prerelease:
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
7
|
+
authors:
|
13
8
|
- Bob Hutchison
|
14
9
|
autorequire:
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
dependencies:
|
21
|
-
- !ruby/object:Gem::Dependency
|
12
|
+
date: 2012-06-08 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
22
15
|
name: xamplr-pp
|
23
|
-
|
24
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
25
17
|
none: false
|
26
|
-
requirements:
|
27
|
-
- -
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
hash: 31
|
30
|
-
segments:
|
31
|
-
- 1
|
32
|
-
- 2
|
33
|
-
- 0
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
34
21
|
version: 1.2.0
|
35
22
|
type: :runtime
|
36
|
-
version_requirements: *id001
|
37
|
-
- !ruby/object:Gem::Dependency
|
38
|
-
name: nokogiri
|
39
23
|
prerelease: false
|
40
|
-
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
25
|
none: false
|
42
|
-
requirements:
|
43
|
-
- -
|
44
|
-
- !ruby/object:Gem::Version
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 1.2.0
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: nokogiri
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
50
37
|
version: 1.4.3
|
51
38
|
type: :runtime
|
52
|
-
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 1.4.3
|
53
46
|
description: xamplr is the ruby version of xampl.
|
54
47
|
email: hutch@recursive.ca
|
55
48
|
executables: []
|
56
|
-
|
57
49
|
extensions: []
|
58
|
-
|
59
|
-
extra_rdoc_files:
|
50
|
+
extra_rdoc_files:
|
60
51
|
- LICENSE
|
61
52
|
- README.md
|
62
|
-
files:
|
53
|
+
files:
|
63
54
|
- .document
|
64
55
|
- .gitignore
|
65
56
|
- CHANGES.txt
|
@@ -169,39 +160,29 @@ files:
|
|
169
160
|
- regression/tightly-nested-mutual-mentions/xampl-gen.rb
|
170
161
|
- regression/tightly-nested-mutual-mentions/xml/stuff.xml
|
171
162
|
- xamplr.gemspec
|
172
|
-
has_rdoc: true
|
173
163
|
homepage: http://github.com/hutch/xamplr
|
174
164
|
licenses: []
|
175
|
-
|
176
165
|
post_install_message:
|
177
|
-
rdoc_options:
|
166
|
+
rdoc_options:
|
178
167
|
- --charset=UTF-8
|
179
|
-
require_paths:
|
168
|
+
require_paths:
|
180
169
|
- lib
|
181
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
170
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
182
171
|
none: false
|
183
|
-
requirements:
|
184
|
-
- -
|
185
|
-
- !ruby/object:Gem::Version
|
186
|
-
|
187
|
-
|
188
|
-
- 0
|
189
|
-
version: "0"
|
190
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
172
|
+
requirements:
|
173
|
+
- - ! '>='
|
174
|
+
- !ruby/object:Gem::Version
|
175
|
+
version: '0'
|
176
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
191
177
|
none: false
|
192
|
-
requirements:
|
193
|
-
- -
|
194
|
-
- !ruby/object:Gem::Version
|
195
|
-
|
196
|
-
segments:
|
197
|
-
- 0
|
198
|
-
version: "0"
|
178
|
+
requirements:
|
179
|
+
- - ! '>='
|
180
|
+
- !ruby/object:Gem::Version
|
181
|
+
version: '0'
|
199
182
|
requirements: []
|
200
|
-
|
201
183
|
rubyforge_project:
|
202
|
-
rubygems_version: 1.
|
184
|
+
rubygems_version: 1.8.24
|
203
185
|
signing_key:
|
204
186
|
specification_version: 3
|
205
187
|
summary: xamplr is the ruby version of xampl
|
206
188
|
test_files: []
|
207
|
-
|