Sha256: e2aca5891f16b47fdd251126d837593095f199278d7ab7448a70389b8cff3c89

Contents?: true

Size: 734 Bytes

Versions: 1

Compression:

Stored size: 734 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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
track_changes-1.0.0.pre1 lib/track_changes/active_record.rb