Module: Historical::Models::Pool

Defined in:
lib/historical/models/pool.rb

Overview

cached classes are stored here

Constant Summary collapse

@@class_pool =
{}

Class Method Summary collapse

Class Method Details

.clear!Object

Removes all stored classes from the pool



18
19
20
21
22
23
24
# File 'lib/historical/models/pool.rb', line 18

def self.clear!
  class_pool.each do |k,v|
    remove_const(k)
  end

  self.class_pool = {}
end

.pooled(name) ⇒ Object

Gets a class from the pool or sets it if the class couldn’t be found.



9
10
11
12
13
14
15
# File 'lib/historical/models/pool.rb', line 9

def self.pooled(name)
  class_pool[name] ||= begin
    yield.tap do |cls|
      const_set(name, cls)
    end
  end
end

.pooled_name(specialized_for, parent) ⇒ Object

Generate unique classnames within the pool.



27
28
29
# File 'lib/historical/models/pool.rb', line 27

def self.pooled_name(specialized_for, parent)
  "#{specialized_for.name.demodulize}#{parent.name.demodulize}"
end