Class: Htmless::Pool
- Inherits:
-
Object
- Object
- Htmless::Pool
- Defined in:
- lib/htmless/pool.rb
Overview
Creating builder instances is expensive, therefore you can use Pool to go around that
Direct Known Subclasses
Defined Under Namespace
Modules: Helper
Instance Attribute Summary (collapse)
-
- (Object) klass
readonly
Returns the value of attribute klass.
Instance Method Summary (collapse)
-
- (Abstract) get
This the preferred way of getting new Builder.
-
- (Pool) initialize(klass)
constructor
A new instance of Pool.
-
- (Object) release(builder)
returns +builder+ back into pool DONT forget to lose the reference to the +builder+.
- - (Object) size
Constructor Details
- (Pool) initialize(klass)
A new instance of Pool
26 27 28 29 30 |
# File 'lib/htmless/pool.rb', line 26 def initialize(klass) @klass = klass @pool = [] klass.send :include, Helper end |
Instance Attribute Details
- (Object) klass (readonly)
Returns the value of attribute klass
24 25 26 |
# File 'lib/htmless/pool.rb', line 24 def klass @klass end |
Instance Method Details
- (Abstract) get
This the preferred way of getting new Builder. If you forget to release it, it does not matter - builder gets GCed after you lose reference
35 36 37 38 39 40 41 |
# File 'lib/htmless/pool.rb', line 35 def get if @pool.empty? @klass.new.instance_exec(self) { |origin| @_origin = origin; self } else @pool.pop end end |
- (Object) release(builder)
returns +builder+ back into pool DONT forget to lose the reference to the +builder+
45 46 47 48 49 50 |
# File 'lib/htmless/pool.rb', line 45 def release(builder) raise TypeError unless builder.is_a? @klass builder.reset @pool.push builder nil end |
- (Object) size
52 53 54 |
# File 'lib/htmless/pool.rb', line 52 def size @pool.size end |