Sha256: 80b89ede333b0288cad0628425ac9446debcd2fa38f4f47d06fcb5a5f05d8d67

Contents?: true

Size: 973 Bytes

Versions: 19

Compression:

Stored size: 973 Bytes

Contents

module ActsAsAuditable

  def self.included(base)
    base.extend(ClassMethods)
  end
  
  module ClassMethods

    def acts_as_auditable(options = {})
      self.cattr_accessor :auditable_options

      class_eval <<-EOV
         include ActsAsAuditable::InstanceMethods
      
         after_create :audit_create
         after_destroy :audit_destroy
         after_update :audit_update
      EOV
      
      acts_as_auditable_options(options)
    end

    def acts_as_auditable_options(options = {})
      self.auditable_options = options
    end    
  end

  module InstanceMethods

    def audit_create
      Appstats::Audit.audit_create(self,self.class.auditable_options)
    end
    
    def audit_destroy
      Appstats::Audit.audit_destroy(self,self.class.auditable_options)
    end
    
    def audit_update
      Appstats::Audit.audit_update(self,self.class.auditable_options)
    end

  end
end       

ActiveRecord::Base.class_eval { include ActsAsAuditable }

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
appstats-0.25.1 lib/appstats/acts_as_auditable.rb
appstats-0.25.0 lib/appstats/acts_as_auditable.rb
appstats-0.24.0 lib/appstats/acts_as_auditable.rb
appstats-0.23.5 lib/appstats/acts_as_auditable.rb
appstats-0.23.4 lib/appstats/acts_as_auditable.rb
appstats-0.23.3 lib/appstats/acts_as_auditable.rb
appstats-0.23.2 lib/appstats/acts_as_auditable.rb
appstats-0.23.1 lib/appstats/acts_as_auditable.rb
appstats-0.23.0 lib/appstats/acts_as_auditable.rb
appstats-0.22.6 lib/appstats/acts_as_auditable.rb
appstats-0.22.5 lib/appstats/acts_as_auditable.rb
appstats-0.22.4 lib/appstats/acts_as_auditable.rb
appstats-0.22.3 lib/appstats/acts_as_auditable.rb
appstats-0.22.2 lib/appstats/acts_as_auditable.rb
appstats-0.22.1 lib/appstats/acts_as_auditable.rb
appstats-0.22.0 lib/appstats/acts_as_auditable.rb
appstats-0.21.3 lib/appstats/acts_as_auditable.rb
appstats-0.21.2 lib/appstats/acts_as_auditable.rb
appstats-0.21.1 lib/appstats/acts_as_auditable.rb