Module: Heron::Factories::Concerns::Eventful

Included in:
Plate
Defined in:
app/models/heron/factories/concerns/eventful.rb

Overview

This module provides a building interface to support creation of events in a factory

Instance Method Summary collapse

Instance Method Details

#add_all_errors_from_event(event) ⇒ Object



25
26
27
# File 'app/models/heron/factories/concerns/eventful.rb', line 25

def add_all_errors_from_event(event)
  event.errors.each { |error| errors.add(error.attribute, error.message) }
end

#add_all_errors_from_events(events) ⇒ Object



21
22
23
# File 'app/models/heron/factories/concerns/eventful.rb', line 21

def add_all_errors_from_events(events)
  events.each { |event| add_all_errors_from_event(event) }
end

#build_events(seed) ⇒ Object



8
9
10
11
12
13
# File 'app/models/heron/factories/concerns/eventful.rb', line 8

def build_events(seed)
  return unless @params[:events]
  return if errors.count.positive?

  params_for_event.map { |event_params| Heron::Factories::Event.new(event_params, seed) }
end

#params_for_eventObject



15
16
17
18
19
# File 'app/models/heron/factories/concerns/eventful.rb', line 15

def params_for_event
  return unless @params

  @params[:events]
end

#rollback_for_events(events) ⇒ Object

Raises:

  • (ActiveRecord::Rollback)


29
30
31
32
33
# File 'app/models/heron/factories/concerns/eventful.rb', line 29

def rollback_for_events(events)
  @output_result = false
  add_all_errors_from_events(events)
  raise ActiveRecord::Rollback
end