Class: SimpleFactory::Factory

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

Class Method Summary collapse

Class Method Details

.create(params = {}) ⇒ Object



7
8
9
10
11
12
13
14
# File 'lib/simple_factory/factory.rb', line 7

def create(params = {})
  definitions = (@definition_samples.sample || [])
  default_params = definitions.map {|d| [d.name, d.value] }.to_h
  merged_params = default_params.merge(params)
  self.new.create(merged_params).tap do |model|
    @after_create_hooks.each {|hook| hook.call(model, merged_params) }
  end
end