Class: ModelFactory::Wrapper

Inherits:
Object
  • Object
show all
Defined in:
lib/modelfactory.rb

Overview

Singleton Factory wrapper class.

Instance Method Summary collapse

Constructor Details

#initialize(&block) ⇒ Wrapper

Create a new FactoryConfiguration with the given block.



34
35
36
37
# File 'lib/modelfactory.rb', line 34

def initialize(&block)
  @config = FactoryConfiguration.new(&block)
  @factory = {}
end

Instance Method Details

#wrap(klass) ⇒ Object

Wraps a given class in a configured Factory instance.



40
41
42
43
44
45
46
47
# File 'lib/modelfactory.rb', line 40

def wrap(klass)
  # We might have a definition for a parent class. If so, use that.
  target = klass
  while target && !@config.class_opts.key?(target)
    target = target.superclass
  end
  @factory[klass] ||= Factory.new(klass, @config.class_opts[target])
end