Sha256: 0a3b5578a13e2df8856c890bff4258089592bc627de6b43cd91fe76df3e718b9

Contents?: true

Size: 798 Bytes

Versions: 2

Compression:

Stored size: 798 Bytes

Contents

module TrackChanges
  module ActiveRecord #:nodoc:
    def self.included(base)
      base.send :extend, ClassMethods
    end

    module ClassMethods

      # Enables auditing of all changes to an ActiveRecord model. Sets up an
      # around filter that will create an Audit for the models <tt>changes</tt>
      # attribute.
      #
      # In addition, this will also define a <tt>attr_accessor</tt> for <tt>current_user</tt>.
      def track_changes
        send :include, TrackChanges::CurrentUser
        send :include, TrackChanges::Changes

        self.class_eval do
          has_many :audits, :as => :audited

          around_save TrackChanges::AroundSave
        end
      end
    end
  end
end

ActiveRecord::Base.send :include, TrackChanges::ActiveRecord

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
track_changes-1.0.0.pre3 lib/track_changes/active_record.rb
track_changes-1.0.0.pre2 lib/track_changes/active_record.rb