Sha256: 23aeeebcc1cd8bef81f2ede652f4a8bd6759596c4f3164cd56046da4af59d923

Contents?: true

Size: 1.13 KB

Versions: 2

Compression:

Stored size: 1.13 KB

Contents

module CollectiveIdea #:nodoc:
  module ActionController #:nodoc:
    module Audited #:nodoc:
      def audit(*models)
        ActiveSupport::Deprecation.warn("#audit is deprecated. Declare #acts_as_audited in your models.", caller)

        options = models.extract_options!

        # Parse the options hash looking for classes
        options.each_key do |key|
          models << [key, options.delete(key)] if key.is_a?(Class)
        end

        models.each do |(model, model_options)|
          model.send :acts_as_audited, model_options || {}
        end
      end
    end
  end
end

class AuditSweeper < ActionController::Caching::Sweeper #:nodoc:
  def before_create(audit)
    audit.send("#{CollectiveIdea::Acts::Audited.human_model}=", current_user) unless audit.send(CollectiveIdea::Acts::Audited.human_model)
  end

  def current_user
    method = "current_#{CollectiveIdea::Acts::Audited.human_model}"
    controller.send(method) if controller.respond_to?(method, true)
  end
end

ActionController::Base.class_eval do
  extend CollectiveIdea::ActionController::Audited
  cache_sweeper :audit_sweeper
end
Audit.add_observer(AuditSweeper.instance)

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
acts_as_audited_customized-1.2.2 lib/acts_as_audited/audit_sweeper.rb
acts_as_audited_customized-1.2.1 lib/acts_as_audited/audit_sweeper.rb