lib/ru_pol.rb in ru_pol-0.1.1 vs lib/ru_pol.rb in ru_pol-0.1.2
- old
+ new
@@ -11,25 +11,29 @@
end
end
module ClassMethods
def _pool
- @pool ||= Pool.new(1000, self)
+ @pool ||= Pool.new(default_pool_size, self)
end
+ def default_pool_size
+ superclass.respond_to?(:_pool) ? superclass._pool.max_size : 1000
+ end
+
def max_pool_size(max_size)
_pool.max_size = max_size
end
def empty_pool!
_pool.empty!
end
- def rehydrate(*init_opts)
+ def rehydrate(*init_opts, &block)
instance = _pool.get
if instance
- instance.instance_eval { init_opts.empty? ? initialize : initialize(*init_opts) }
+ instance.instance_eval { init_opts.empty? ? initialize(&block) : initialize(*init_opts, &block) }
end
instance
end
end
@@ -67,11 +71,11 @@
recycle
end
end
module ClassMethods
- def new(*init_opts)
- rehydrate(*init_opts) || ( init_opts.empty? ? super() : super(*init_opts) )
+ def new(*init_opts, &block)
+ rehydrate(*init_opts, &block) || ( init_opts.empty? ? super() : super(*init_opts) )
end
end
end
end
\ No newline at end of file