ru_pol 0.1.1 → 0.1.2
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/VERSION +1 -1
- data/lib/ru_pol.rb +9 -5
- data/ru_pol.gemspec +2 -2
- data/spec/ru_pol_spec.rb +42 -0
- metadata +4 -4
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.2
|
data/lib/ru_pol.rb
CHANGED
@@ -13,7 +13,11 @@ module RuPol
|
|
13
13
|
|
14
14
|
module ClassMethods
|
15
15
|
def _pool
|
16
|
-
@pool ||= Pool.new(
|
16
|
+
@pool ||= Pool.new(default_pool_size, self)
|
17
|
+
end
|
18
|
+
|
19
|
+
def default_pool_size
|
20
|
+
superclass.respond_to?(:_pool) ? superclass._pool.max_size : 1000
|
17
21
|
end
|
18
22
|
|
19
23
|
def max_pool_size(max_size)
|
@@ -24,10 +28,10 @@ module RuPol
|
|
24
28
|
_pool.empty!
|
25
29
|
end
|
26
30
|
|
27
|
-
def rehydrate(*init_opts)
|
31
|
+
def rehydrate(*init_opts, &block)
|
28
32
|
instance = _pool.get
|
29
33
|
if instance
|
30
|
-
instance.instance_eval { init_opts.empty? ? initialize : initialize(*init_opts) }
|
34
|
+
instance.instance_eval { init_opts.empty? ? initialize(&block) : initialize(*init_opts, &block) }
|
31
35
|
end
|
32
36
|
instance
|
33
37
|
end
|
@@ -69,8 +73,8 @@ module RuPol
|
|
69
73
|
end
|
70
74
|
|
71
75
|
module ClassMethods
|
72
|
-
def new(*init_opts)
|
73
|
-
rehydrate(*init_opts) || ( init_opts.empty? ? super() : super(*init_opts) )
|
76
|
+
def new(*init_opts, &block)
|
77
|
+
rehydrate(*init_opts, &block) || ( init_opts.empty? ? super() : super(*init_opts) )
|
74
78
|
end
|
75
79
|
end
|
76
80
|
end
|
data/ru_pol.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{ru_pol}
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.2"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Kane Baccigalupi"]
|
12
|
-
s.date = %q{2011-
|
12
|
+
s.date = %q{2011-04-12}
|
13
13
|
s.description = %q{RuPol is a glamorous mixin for instance pooling your Ruby classes.
|
14
14
|
It eases the pain of garbarge collection for classes that are instantiated many times, and then tossed away like runway trash.
|
15
15
|
Instances are cached on the class in a pool (array in less glamorous terms), and can be recycled at will.
|
data/spec/ru_pol_spec.rb
CHANGED
@@ -26,6 +26,19 @@ describe RuPol do
|
|
26
26
|
Irreplacable._pool.max_size.should == 1000
|
27
27
|
end
|
28
28
|
|
29
|
+
it 'sets the default size to the size of it superclass if it has one' do
|
30
|
+
class BigPool
|
31
|
+
include RuPol::Swimsuit
|
32
|
+
max_pool_size 10000
|
33
|
+
end
|
34
|
+
|
35
|
+
BigPool._pool.max_size.should == 10000
|
36
|
+
|
37
|
+
class BigPoolDescendant < BigPool; end
|
38
|
+
|
39
|
+
BigPoolDescendant._pool.max_size.should == 10000
|
40
|
+
end
|
41
|
+
|
29
42
|
it 'pool max size is settable via the #max_pool_size class method' do
|
30
43
|
Irreplacable.max_pool_size 42
|
31
44
|
Irreplacable._pool.max_size.should == 42
|
@@ -245,6 +258,35 @@ describe RuPol do
|
|
245
258
|
end
|
246
259
|
end
|
247
260
|
|
261
|
+
describe 'blocks' do
|
262
|
+
class Blocky
|
263
|
+
attr_accessor :has_block
|
264
|
+
include RuPol::Swimsuit
|
265
|
+
def initialize(&block)
|
266
|
+
self.has_block = block_given?
|
267
|
+
end
|
268
|
+
end
|
269
|
+
|
270
|
+
before do
|
271
|
+
Blocky.empty_pool!
|
272
|
+
end
|
273
|
+
|
274
|
+
it 'passes the block along on a brand new object' do
|
275
|
+
blocky = Blocky.new { "oh yes, it is!" }
|
276
|
+
blocky.has_block.should be_true
|
277
|
+
end
|
278
|
+
|
279
|
+
it 'passes the block to recycled items on reinit' do
|
280
|
+
blocky = Blocky.new { "first run" }
|
281
|
+
blocky.has_block.should be_true
|
282
|
+
blocky.recycle
|
283
|
+
blocky.has_block.should be_nil
|
284
|
+
|
285
|
+
new_blocky = Blocky.new { "and again" }
|
286
|
+
new_blocky.has_block.should be_true
|
287
|
+
end
|
288
|
+
end
|
289
|
+
|
248
290
|
describe 'rehydrating' do
|
249
291
|
before do
|
250
292
|
[
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ru_pol
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 31
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 2
|
10
|
+
version: 0.1.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Kane Baccigalupi
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-
|
18
|
+
date: 2011-04-12 00:00:00 -07:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|