Class: Falcor::Fabricator

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

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Class Attribute Details

.factoriesObject

Returns the value of attribute factories.



6
7
8
# File 'lib/falcor/fabricator.rb', line 6

def factories
  @factories
end

Class Method Details

.create(name, overrides, block) ⇒ Object



12
13
14
15
16
# File 'lib/falcor/fabricator.rb', line 12

def create(name, overrides, block)
  raise "No factory defined: [#{name}]" unless factories.has_key?(name)

  factories[name].create(overrides)
end

.define(name, options = {}, &block) ⇒ Object



8
9
10
# File 'lib/falcor/fabricator.rb', line 8

def define(name, options={}, &block)
  factories[name] = self.new({ :name => name, :block => block }.merge(options))
end

Instance Method Details

#create(overrides) ⇒ Object



19
20
21
22
23
24
25
26
# File 'lib/falcor/fabricator.rb', line 19

def create(overrides)
  @options = @definition.merge(overrides)
  @options[:super] = Factory if @options[:super].nil?
  klass = create_class
  klass.create_methods(@options[:block])

  klass.new(overrides)
end