Sha256: bd822df29e1503cc91be79c391122f26c0d67b25ae952d8373ca9ed9ba3ee0e5

Contents?: true

Size: 887 Bytes

Versions: 7

Compression:

Stored size: 887 Bytes

Contents

# frozen_string_literal: true

# Copyright (c) 2008-2013 Michael Dvorkin and contributors.
#
# Fat Free CRM is freely distributable under the terms of MIT license.
# See MIT-LICENSE file or http://www.opensource.org/licenses/mit-license.php
#------------------------------------------------------------------------------
class LeadObserver < ActiveRecord::Observer
  observe :lead

  @@leads = {}

  def before_update(item)
    @@leads[item.id] = Lead.find(item.id).freeze
  end

  def after_update(item)
    original = @@leads.delete(item.id)
    return log_activity(item, :reject) if original&.status != "rejected" && item.status == "rejected"
  end

  private

  def log_activity(item, event)
    item.send(item.class.versions_association_name).create(event: event, whodunnit: PaperTrail.request.whodunnit)
  end

  ActiveSupport.run_load_hooks(:fat_free_crm_lead_observer, self)
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
fat_free_crm-0.22.1 app/models/observers/lead_observer.rb
fat_free_crm-0.22.0 app/models/observers/lead_observer.rb
fat_free_crm-0.21.0 app/models/observers/lead_observer.rb
fat_free_crm-0.20.1 app/models/observers/lead_observer.rb
fat_free_crm-0.20.0 app/models/observers/lead_observer.rb
fat_free_crm-0.19.2 app/models/observers/lead_observer.rb
fat_free_crm-0.19.0 app/models/observers/lead_observer.rb