Class: ActionFactory::ActiveRecord::Association

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

Instance Method Summary collapse

Constructor Details

#initialize(strategy:, factory_name:, traits:, block:) ⇒ Association

Returns a new instance of Association.



11
12
13
14
15
16
# File 'lib/action_factory/active_record.rb', line 11

def initialize(strategy:, factory_name:, traits:, block:)
  @strategy = strategy
  @factory_name = factory_name
  @traits = traits
  @block = block
end

Instance Method Details

#generate(strategy) ⇒ Object



18
19
20
# File 'lib/action_factory/active_record.rb', line 18

def generate(strategy)
  @block ? @block.call(runner) : runner.run(strategy)
end

#runnerObject



22
23
24
# File 'lib/action_factory/active_record.rb', line 22

def runner
  @runner ||= ActionFactory::Runner.new(@factory_name, *@traits, strategy: @strategy)
end