Class: GenericCountingPool
- Inherits:
- 
      GenericPool
      
        - Object
- GenericPool
- GenericCountingPool
 
- Defined in:
- lib/volt/utils/generic_counting_pool.rb
Overview
A counting pool behaves like a normal GenericPool, except for each time lookup is called, remove should be called when complete. The item will be completely removed from the GenericCountingPool only when it has been removed an equal number of times it has been looked up.
Direct Known Subclasses
Instance Attribute Summary
Attributes inherited from GenericPool
Instance Method Summary collapse
- 
  
    
      #find(*args, &block)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    Finds an item and tracks that it was checked out. 
- 
  
    
      #generate_new(*args)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    return a created item with a count. 
- 
  
    
      #lookup(*args, &block)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    Lookups an item. 
- #remove(*args) ⇒ Object
- #transform_item(item) ⇒ Object
Methods inherited from GenericPool
#create_new_item, #initialize, #lookup_all
Constructor Details
This class inherits a constructor from GenericPool
Instance Method Details
#find(*args, &block) ⇒ Object
Finds an item and tracks that it was checked out. Use #remove when the item is no longer needed.
| 16 17 18 19 20 21 22 | # File 'lib/volt/utils/generic_counting_pool.rb', line 16 def find(*args, &block) item = __lookup(*args, &block) item[0] += 1 return item[1] end | 
#generate_new(*args) ⇒ Object
return a created item with a count
| 10 11 12 | # File 'lib/volt/utils/generic_counting_pool.rb', line 10 def generate_new(*args) [0, create(*args)] end | 
#lookup(*args, &block) ⇒ Object
Lookups an item
| 25 26 27 28 29 | # File 'lib/volt/utils/generic_counting_pool.rb', line 25 def lookup(*args, &block) item = super(*args, &block) return item[1] end | 
#remove(*args) ⇒ Object
| 35 36 37 38 39 40 41 42 43 | # File 'lib/volt/utils/generic_counting_pool.rb', line 35 def remove(*args) item = __lookup(*args) item[0] -= 1 if item[0] == 0 # Last one using this item has removed it. super(*args) end end | 
#transform_item(item) ⇒ Object
| 31 32 33 | # File 'lib/volt/utils/generic_counting_pool.rb', line 31 def transform_item(item) [0, item] end |