Class: ActionJob
- Inherits:
-
Struct
- Object
- Struct
- ActionJob
- Defined in:
- app/models/job/action_job.rb
Overview
Callers should:
-
set all relevant details on :action including org and creator.
-
call action.to_open_struct, then pass that struct to this Job
If action.subject is not set, subject will be set to person_id
Instance Attribute Summary collapse
-
#action_struct ⇒ Object
Returns the value of attribute action_struct.
-
#people_ids ⇒ Object
Returns the value of attribute people_ids.
Instance Method Summary collapse
-
#initialize(action, people) ⇒ ActionJob
constructor
A new instance of ActionJob.
- #perform ⇒ Object
Constructor Details
#initialize(action, people) ⇒ ActionJob
Returns a new instance of ActionJob.
9 10 11 12 |
# File 'app/models/job/action_job.rb', line 9 def initialize(action, people) self.action_struct = action.to_open_struct self.people_ids = Array.wrap(people).map(&:id) end |
Instance Attribute Details
#action_struct ⇒ Object
Returns the value of attribute action_struct
8 9 10 |
# File 'app/models/job/action_job.rb', line 8 def action_struct @action_struct end |
#people_ids ⇒ Object
Returns the value of attribute people_ids
8 9 10 |
# File 'app/models/job/action_job.rb', line 8 def people_ids @people_ids end |
Instance Method Details
#perform ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'app/models/job/action_job.rb', line 14 def perform action = Action.from_open_struct(self.action_struct) ActiveRecord::Base.transaction do Person.where(:id => self.people_ids).each do |p| if action.organization_id != p.organization_id raise "Org id on action #{action.organization_id} does not equal org id on person with id #{p.id}" end new_action = action.dup new_action.subject_id ||= p.id new_action.person = p new_action.save end end end |