Sha256: d1d2810db762723825b7a4fc177a89b03d0268c92ae9917680af6bdc935c88cd

Contents?: true

Size: 918 Bytes

Versions: 35

Compression:

Stored size: 918 Bytes

Contents

#
# 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 
#
class ActionJob < Struct.new(:action_struct, :people_ids)
  def initialize(action, people)
    self.action_struct = action.to_open_struct
    self.people_ids = Array.wrap(people).map(&:id)
  end

  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
end

Version data entries

35 entries across 35 versions & 1 rubygems

Version Path
artfully_ose-1.3.0.pre4 app/models/job/action_job.rb
artfully_ose-1.3.0.pre3 app/models/job/action_job.rb
artfully_ose-1.3.0.pre2 app/models/job/action_job.rb
artfully_ose-1.3.0.pre1 app/models/job/action_job.rb
artfully_ose-1.2.0 app/models/job/action_job.rb
artfully_ose-1.2.0.beta.1 app/models/job/action_job.rb
artfully_ose-1.2.0.alpha.2 app/models/job/action_job.rb
artfully_ose-1.2.0.alpha.1 app/models/job/action_job.rb
artfully_ose-1.2.0.pre.27 app/models/job/action_job.rb
artfully_ose-1.2.0.pre.26 app/models/job/action_job.rb
artfully_ose-1.2.0.pre.24 app/models/job/action_job.rb
artfully_ose-1.2.0.pre.23 app/models/job/action_job.rb
artfully_ose-1.2.0.pre.21 app/models/job/action_job.rb
artfully_ose-1.2.0.pre.20 app/models/job/action_job.rb
artfully_ose-1.2.0.pre.19 app/models/job/action_job.rb
artfully_ose-1.2.0.pre.18 app/models/job/action_job.rb
artfully_ose-1.2.0.pre.17 app/models/job/action_job.rb
artfully_ose-1.2.0.pre.16 app/models/job/action_job.rb
artfully_ose-1.2.0.pre.15 app/models/job/action_job.rb
artfully_ose-1.2.0.pre.12 app/models/job/action_job.rb