io_shuten 0.0.1.dev5 → 0.0.3.dev1
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/.travis.yml +7 -0
- data/Gemfile +3 -4
- data/Gemfile.lock +2 -8
- data/README.md +17 -3
- data/Rakefile +25 -1
- data/benchmark/compare_mem_w_buf.rb +134 -0
- data/doc/IO_3A_3ABuffer.html +198 -0
- data/doc/IO_shuten/Base.html +349 -1943
- data/doc/IO_shuten/Buffer.html +1842 -0
- data/doc/IO_shuten/Errors/FileAccessError.html +5 -4
- data/doc/IO_shuten/Errors/FileNotFoundError.html +5 -4
- data/doc/IO_shuten/Errors/NodeExistsError.html +5 -4
- data/doc/IO_shuten/Errors/NodeNameError.html +5 -4
- data/doc/IO_shuten/Errors/NodeNotFoundError.html +5 -4
- data/doc/IO_shuten/Errors/NotYetImplemented.html +5 -4
- data/doc/IO_shuten/Errors.html +5 -4
- data/doc/IO_shuten/Memory.html +1798 -0
- data/doc/IO_shuten/Mongo.html +9 -13
- data/doc/IO_shuten/Redis.html +803 -8
- data/doc/IO_shuten/Stores/Mongo/Collection.html +5 -4
- data/doc/IO_shuten/Stores/Mongo/GridFS.html +5 -4
- data/doc/IO_shuten/Stores/Mongo.html +5 -4
- data/doc/IO_shuten/Stores/Redis/KeyValue.html +5 -4
- data/doc/IO_shuten/Stores/Redis/PubSub.html +5 -4
- data/doc/IO_shuten/Stores/Redis.html +5 -4
- data/doc/IO_shuten/Stores.html +5 -4
- data/doc/IO_shuten.html +7 -6
- data/doc/_index.html +20 -6
- data/doc/class_list.html +1 -1
- data/doc/file.README.html +21 -6
- data/doc/index.html +21 -6
- data/doc/method_list.html +119 -15
- data/doc/top-level-namespace.html +2 -2
- data/io_shuten.gemspec +16 -12
- data/lib/io_shuten/base.rb +1 -129
- data/lib/io_shuten/buffer.rb +156 -0
- data/lib/io_shuten/memory.rb +145 -0
- data/lib/io_shuten/redis.rb +65 -0
- data/lib/io_shuten/version.rb +1 -1
- data/lib/io_shuten.rb +2 -0
- data/spec/examples/logger_spec.rb +18 -2
- data/spec/lib/buffer_spec.rb +387 -0
- data/spec/lib/{base_spec.rb → memory_spec.rb} +92 -82
- data/spec/lib/mongo_spec.rb +1 -1
- data/spec/lib/redis_spec.rb +1 -1
- data/spec/spec_helper.rb +16 -12
- metadata +233 -163
@@ -2,42 +2,42 @@
|
|
2
2
|
require File.expand_path("../../spec_helper.rb", __FILE__)
|
3
3
|
|
4
4
|
include IO_shuten
|
5
|
-
describe
|
5
|
+
describe Memory do
|
6
6
|
|
7
7
|
describe "Class Methods" do
|
8
8
|
|
9
9
|
describe :new do
|
10
10
|
|
11
11
|
context "without node_name" do
|
12
|
-
it "raises " do
|
13
|
-
expect {
|
12
|
+
it "raises Errors::NodeNameError" do
|
13
|
+
expect { Memory.new }.to raise_error(Errors::NodeNameError)
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
17
|
context "with node_name" do
|
18
18
|
it "creates a new node with name as String" do
|
19
19
|
node_name = "foo bar"
|
20
|
-
|
21
|
-
|
22
|
-
|
20
|
+
iom = Memory.new(node_name)
|
21
|
+
iom.should be_an(IO_shuten::Memory)
|
22
|
+
iom.node_name.should == node_name
|
23
23
|
end
|
24
24
|
|
25
25
|
it "creates a new node with name as Symbol" do
|
26
26
|
node_name = :foobar
|
27
|
-
|
28
|
-
|
29
|
-
|
27
|
+
iom = Memory.new(node_name)
|
28
|
+
iom.should be_an(IO_shuten::Memory)
|
29
|
+
iom.node_name.should == node_name
|
30
30
|
end
|
31
31
|
|
32
32
|
it "raises NodeNameError if wrong type" do
|
33
33
|
node_name = 1.23
|
34
|
-
expect {
|
34
|
+
expect { Memory.new(node_name) }.to raise_error(Errors::NodeNameError)
|
35
35
|
end
|
36
36
|
|
37
37
|
it "raises NodeExistsError if node name is already taken" do
|
38
38
|
node_name = :already_taken
|
39
|
-
expect {
|
40
|
-
expect {
|
39
|
+
expect { Memory.new(node_name) }.to_not raise_error
|
40
|
+
expect { Memory.new(node_name) }.to raise_error(Errors::NodeExistsError)
|
41
41
|
end
|
42
42
|
end
|
43
43
|
|
@@ -46,52 +46,52 @@ describe Base do
|
|
46
46
|
describe "class based memory storage" do
|
47
47
|
describe :purge_instances! do
|
48
48
|
it "purges all instances" do
|
49
|
-
|
50
|
-
|
49
|
+
Memory.purge_instances!
|
50
|
+
Memory.instances.should have(0).items
|
51
51
|
end
|
52
52
|
end
|
53
53
|
|
54
54
|
describe :instances do
|
55
55
|
it "retrieves all @@instances" do
|
56
|
-
|
56
|
+
Memory.purge_instances!
|
57
57
|
nodes = %w[first second last]
|
58
58
|
nodes.each do |node_name|
|
59
|
-
|
59
|
+
Memory.new(node_name)
|
60
60
|
end
|
61
61
|
|
62
|
-
|
62
|
+
Memory.instances.should have(3).items
|
63
63
|
end
|
64
64
|
end
|
65
65
|
|
66
66
|
describe :delete_instance do
|
67
67
|
before do
|
68
|
-
|
68
|
+
Memory.purge_instances!
|
69
69
|
@node_names = %w[first second last]
|
70
70
|
@nodes = @node_names.inject([]) do |store, node_name|
|
71
|
-
store <<
|
71
|
+
store << Memory.new(node_name)
|
72
72
|
store
|
73
73
|
end
|
74
74
|
end
|
75
75
|
|
76
76
|
it "removes an node by name from store" do
|
77
|
-
|
78
|
-
|
77
|
+
Memory.delete_instance(@node_names.first)
|
78
|
+
Memory.instances.should_not include(@nodes.first)
|
79
79
|
end
|
80
80
|
|
81
81
|
it "removes an node by instance from store" do
|
82
|
-
|
83
|
-
|
82
|
+
Memory.delete_instance(@nodes.first)
|
83
|
+
Memory.instances.should_not include(@nodes.first)
|
84
84
|
end
|
85
85
|
|
86
86
|
it "removes an node by symbolized name from store" do
|
87
|
-
|
87
|
+
Memory.purge_instances!
|
88
88
|
@node_names = %w[first second last].map(&:to_sym)
|
89
89
|
@nodes = @node_names.inject([]) do |store, node_name|
|
90
|
-
store <<
|
90
|
+
store << Memory.new(node_name)
|
91
91
|
store
|
92
92
|
end
|
93
|
-
|
94
|
-
|
93
|
+
Memory.delete_instance(@node_names.first)
|
94
|
+
Memory.instances.should_not include(@nodes.first)
|
95
95
|
end
|
96
96
|
|
97
97
|
end
|
@@ -99,7 +99,7 @@ describe Base do
|
|
99
99
|
describe "batch tasks" do
|
100
100
|
|
101
101
|
before do
|
102
|
-
|
102
|
+
Memory.purge_instances!
|
103
103
|
|
104
104
|
@tmp_path = File.expand_path("../../../tmp", __FILE__)
|
105
105
|
|
@@ -121,7 +121,7 @@ describe Base do
|
|
121
121
|
@file_names.each do |file_name|
|
122
122
|
File.unlink("#{@tmp_path}/#{file_name}") if File.exists?("#{@tmp_path}/#{file_name}")
|
123
123
|
end
|
124
|
-
|
124
|
+
Memory.purge_instances!
|
125
125
|
end
|
126
126
|
|
127
127
|
describe :save_instances do
|
@@ -137,11 +137,11 @@ describe Base do
|
|
137
137
|
|
138
138
|
it "writes all instances to disk" do
|
139
139
|
@file_names2.each do |file_name|
|
140
|
-
node =
|
140
|
+
node = Memory.new("#{@tmp_path}/#{file_name}")
|
141
141
|
node.puts "content of file: #{file_name}"
|
142
142
|
end
|
143
143
|
|
144
|
-
|
144
|
+
Memory.save_instances.should be_true
|
145
145
|
end
|
146
146
|
end
|
147
147
|
|
@@ -150,18 +150,18 @@ describe Base do
|
|
150
150
|
absolute_files = @file_names.inject([]) do |store, file_name|
|
151
151
|
store << "#{@tmp_path}/#{file_name}"
|
152
152
|
end
|
153
|
-
|
154
|
-
|
153
|
+
Memory.load_instances absolute_files
|
154
|
+
Memory.pool.should have(3).items
|
155
155
|
end
|
156
156
|
|
157
157
|
it "loads an array of files provided by Dir.glob" do
|
158
|
-
|
159
|
-
|
158
|
+
Memory.load_instances Dir.glob(@tmp_path+"/**/*")
|
159
|
+
Memory.pool.should have(3).items
|
160
160
|
end
|
161
161
|
|
162
162
|
it "loads files from a directory name (String)" do
|
163
|
-
|
164
|
-
|
163
|
+
Memory.load_instances @tmp_path
|
164
|
+
Memory.pool.should have(3).items
|
165
165
|
end
|
166
166
|
end
|
167
167
|
|
@@ -173,12 +173,12 @@ describe Base do
|
|
173
173
|
describe :open do
|
174
174
|
|
175
175
|
before do
|
176
|
-
|
176
|
+
Memory.purge_instances!
|
177
177
|
end
|
178
178
|
|
179
179
|
context "without any args" do
|
180
180
|
it "raises ArgumentError" do
|
181
|
-
expect {
|
181
|
+
expect { Memory.open }.to raise_error(::ArgumentError)
|
182
182
|
end
|
183
183
|
end
|
184
184
|
|
@@ -186,26 +186,26 @@ describe Base do
|
|
186
186
|
|
187
187
|
context "and node does not exist" do
|
188
188
|
it "raises NodeNotFound error" do
|
189
|
-
expect {
|
189
|
+
expect { Memory.open("foo bar") }.to raise_error(Errors::NodeNotFoundError)
|
190
190
|
end
|
191
191
|
end
|
192
192
|
|
193
193
|
context "and node exists" do
|
194
194
|
it "returns the requested node" do
|
195
195
|
node_name = "foo bar"
|
196
|
-
stored_obj =
|
196
|
+
stored_obj = Memory.new(node_name)
|
197
197
|
|
198
|
-
|
199
|
-
|
198
|
+
iom = Memory.open(node_name)
|
199
|
+
iom.should === stored_obj
|
200
200
|
end
|
201
201
|
|
202
202
|
it "always reopens node for writing (and reading)" do
|
203
203
|
node_name = :always_reopenable
|
204
|
-
node =
|
204
|
+
node = Memory.new(node_name)
|
205
205
|
node.close
|
206
206
|
|
207
207
|
node.should be_closed
|
208
|
-
|
208
|
+
Memory.open(node_name).should_not be_closed
|
209
209
|
end
|
210
210
|
end
|
211
211
|
end
|
@@ -213,9 +213,9 @@ describe Base do
|
|
213
213
|
context "with name and block" do
|
214
214
|
it "opens node, yields the block and closes node for writing" do
|
215
215
|
str = "string set in block"
|
216
|
-
origin =
|
216
|
+
origin = Memory.new(:blocktest)
|
217
217
|
|
218
|
-
open_obj =
|
218
|
+
open_obj = Memory.open :blocktest do |handle|
|
219
219
|
handle.write str
|
220
220
|
end
|
221
221
|
|
@@ -229,18 +229,18 @@ describe Base do
|
|
229
229
|
it "can reopen an node for manipulation" do
|
230
230
|
str = "string set in block"
|
231
231
|
other_str = "new string"
|
232
|
-
origin =
|
232
|
+
origin = Memory.new(:blocktest)
|
233
233
|
|
234
|
-
|
234
|
+
Memory.open :blocktest do |handle|
|
235
235
|
handle.write str
|
236
236
|
end
|
237
237
|
|
238
238
|
expect do
|
239
|
-
|
239
|
+
Memory.open :blocktest do |handle|
|
240
240
|
handle.puts other_str
|
241
241
|
end
|
242
242
|
end.to_not raise_error
|
243
|
-
|
243
|
+
Memory.open(:blocktest).string.should match(other_str)
|
244
244
|
end
|
245
245
|
end
|
246
246
|
|
@@ -251,7 +251,7 @@ describe Base do
|
|
251
251
|
describe "Instance Methods" do
|
252
252
|
|
253
253
|
before do
|
254
|
-
|
254
|
+
Memory.purge_instances!
|
255
255
|
end
|
256
256
|
|
257
257
|
describe "StringIO method wrapper (for: #{RUBY_VERSION})" do
|
@@ -283,19 +283,29 @@ describe Base do
|
|
283
283
|
ungetbyte
|
284
284
|
write_nonblock
|
285
285
|
]
|
286
|
+
rbx19_excludes = %w[
|
287
|
+
codepoints
|
288
|
+
each_codepoint
|
289
|
+
external_encoding
|
290
|
+
internal_encoding
|
291
|
+
set_encoding
|
292
|
+
ungetbyte
|
293
|
+
write_nonblock
|
294
|
+
]
|
286
295
|
method_list = RUBY_VERSION =~ /^1\.8\./ ? m18 : (m18 + m19_additionals)
|
296
|
+
method_list = (RUBY_ENGINE == 'rbx' && RUBY_VERSION =~ /^1\.9\./) ? (m18 + m19_additionals - rbx19_excludes) : method_list
|
287
297
|
|
288
298
|
method_list.each do |method_name|
|
289
299
|
it "- responds to ##{method_name}" do
|
290
|
-
|
300
|
+
Memory.new(:string_io_test).should respond_to(method_name)
|
291
301
|
end
|
292
302
|
end
|
293
303
|
end
|
294
304
|
|
295
305
|
describe "method stub with #not_yet_implemented! call" do
|
296
306
|
it "raises NotYetImplemented" do
|
297
|
-
|
298
|
-
|
307
|
+
iom = Memory.new(:not_implemented)
|
308
|
+
iom.instance_eval do
|
299
309
|
def not_implemented_method_a
|
300
310
|
not_yet_implemented!
|
301
311
|
end
|
@@ -303,9 +313,9 @@ describe Base do
|
|
303
313
|
not_yet_implemented! __method__, "#{__FILE__}:#{__LINE__}"
|
304
314
|
end
|
305
315
|
end
|
306
|
-
expect {
|
307
|
-
expect {
|
308
|
-
expect {
|
316
|
+
expect { iom.not_implemented_method_a }.to raise_error(Errors::NotYetImplemented)
|
317
|
+
expect { iom.not_implemented_method_b }.to raise_error(Errors::NotYetImplemented)
|
318
|
+
expect { iom.not_implemented_method_c }.to raise_error(Errors::NotYetImplemented)
|
309
319
|
end
|
310
320
|
end
|
311
321
|
|
@@ -327,24 +337,24 @@ describe Base do
|
|
327
337
|
after do
|
328
338
|
File.unlink(@tmp_true_file)
|
329
339
|
File.unlink(@tmp_save_file) if File.exists?(@tmp_save_file)
|
330
|
-
|
340
|
+
Memory.purge_instances!
|
331
341
|
end
|
332
342
|
|
333
343
|
describe :file_exists? do
|
334
344
|
|
335
345
|
it "returns true if path is a file" do
|
336
|
-
|
337
|
-
|
346
|
+
iom = Memory.new(@tmp_true_file)
|
347
|
+
iom.file_exists?.should be_true
|
338
348
|
end
|
339
349
|
|
340
350
|
it "returns true if custom path is a file" do
|
341
|
-
|
342
|
-
|
351
|
+
iom = Memory.new(:different_name)
|
352
|
+
iom.file_exists?(@tmp_true_file).should be_true
|
343
353
|
end
|
344
354
|
|
345
355
|
it "returns false if path is not a file" do
|
346
|
-
|
347
|
-
|
356
|
+
iom = Memory.new(@tmp_false_file)
|
357
|
+
iom.file_exists?.should be_false
|
348
358
|
end
|
349
359
|
|
350
360
|
end
|
@@ -354,23 +364,23 @@ describe Base do
|
|
354
364
|
context "file exists" do
|
355
365
|
|
356
366
|
it "reads file and stores content into container" do
|
357
|
-
|
358
|
-
|
359
|
-
|
367
|
+
iom = Memory.new(@tmp_true_file)
|
368
|
+
iom.load_from_file.should be_true
|
369
|
+
iom.string.should =~ /true content/
|
360
370
|
end
|
361
371
|
|
362
372
|
it "reads file with custom name" do
|
363
|
-
|
364
|
-
|
365
|
-
|
373
|
+
iom = Memory.new(:different_name)
|
374
|
+
iom.load_from_file(@tmp_true_file).should be_true
|
375
|
+
iom.string.should =~ /content/
|
366
376
|
end
|
367
377
|
|
368
378
|
end
|
369
379
|
|
370
380
|
context "file does not exist" do
|
371
381
|
it "raises FileNotFoundError" do
|
372
|
-
|
373
|
-
expect {
|
382
|
+
iom = Memory.new(@tmp_false_file)
|
383
|
+
expect { iom.load_from_file }.to raise_error(Errors::FileNotFoundError)
|
374
384
|
end
|
375
385
|
end
|
376
386
|
|
@@ -381,17 +391,17 @@ describe Base do
|
|
381
391
|
context "file path accessible" do
|
382
392
|
context "with container name as default" do
|
383
393
|
it "writes container into the file" do
|
384
|
-
|
385
|
-
|
386
|
-
|
394
|
+
iom = Memory.new(@tmp_save_file)
|
395
|
+
iom.puts "Test string"
|
396
|
+
iom.save_to_file.should be_true
|
387
397
|
end
|
388
398
|
end
|
389
399
|
|
390
400
|
context "with custom name" do
|
391
401
|
it "writes container into the file" do
|
392
|
-
|
393
|
-
|
394
|
-
|
402
|
+
iom = Memory.new(:different_name)
|
403
|
+
iom.puts "Test string"
|
404
|
+
iom.save_to_file(@tmp_save_file).should be_true
|
395
405
|
end
|
396
406
|
end
|
397
407
|
|
@@ -399,9 +409,9 @@ describe Base do
|
|
399
409
|
|
400
410
|
context "path not accessible" do
|
401
411
|
it "raises FileAccessError with corresponding reason" do
|
402
|
-
|
403
|
-
|
404
|
-
expect {
|
412
|
+
iom = Memory.new(@denied_path)
|
413
|
+
iom.puts "Test string"
|
414
|
+
expect { iom.save_to_file }.to raise_error(Errors::FileAccessError, /Reason/)
|
405
415
|
end
|
406
416
|
end
|
407
417
|
|
data/spec/lib/mongo_spec.rb
CHANGED
data/spec/lib/redis_spec.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -6,26 +6,30 @@ require "io_shuten"
|
|
6
6
|
|
7
7
|
### MONKEY PATCH raise
|
8
8
|
|
9
|
+
RUBY_ENGINE = '(no engine)' unless defined? RUBY_ENGINE
|
10
|
+
|
9
11
|
# usage: raise my_instance
|
10
12
|
# raise :foo
|
11
13
|
# raise anything_else_which_is_an_object
|
12
14
|
# raise foo.bar.baz
|
13
15
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
16
|
+
unless RUBY_ENGINE == 'rbx' && RUBY_VERSION =~ /^1\.9\./
|
17
|
+
class Module
|
18
|
+
def alias_method_chain( target, feature )
|
19
|
+
alias_method "#{target}_without_#{feature}", target
|
20
|
+
alias_method target, "#{target}_with_#{feature}"
|
21
|
+
end
|
18
22
|
end
|
19
|
-
end
|
20
23
|
|
21
|
-
class Object
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
24
|
+
class Object
|
25
|
+
def raise_with_helpfulness(*args)
|
26
|
+
raise_without_helpfulness(*args)
|
27
|
+
rescue TypeError => e
|
28
|
+
raise_without_helpfulness args.first.inspect if ['exception class/object expected', 'exception object expected'].include?(e.to_s)
|
29
|
+
raise_without_helpfulness e
|
30
|
+
end
|
31
|
+
alias_method_chain :raise, :helpfulness
|
27
32
|
end
|
28
|
-
alias_method_chain :raise, :helpfulness
|
29
33
|
end
|
30
34
|
|
31
35
|
### Custom Matchers
|