Sha256: 4335274544dc6c3f2262b6fe95338d347733907e34f0d14b65913a2854f3a8e3

Contents?: true

Size: 698 Bytes

Versions: 46

Compression:

Stored size: 698 Bytes

Contents

module Piggybak
  module ActsAsChanger
    extend ActiveSupport::Concern

    module ClassMethods
      def acts_as_changer
        after_create :document_new_item
        after_update :document_nested_change
        after_destroy :document_destroy_item
      end
    end

    def document_new_item
      self.order.recorded_changes << self.new_destroy_changes("added")
    end

    def document_nested_change
      if self.changed?
        self.order.recorded_changes << self.formatted_changes
      end
    end

    def document_destroy_item
      self.order.recorded_changes << self.new_destroy_changes("destroyed")
    end
  end
end

::ActiveRecord::Base.send :include, Piggybak::ActsAsChanger

Version data entries

46 entries across 46 versions & 1 rubygems

Version Path
piggybak-0.6.1 lib/acts_as_changer.rb
piggybak-0.6.0 lib/acts_as_changer.rb
piggybak-0.5.5 lib/acts_as_changer.rb
piggybak-0.5.4 lib/acts_as_changer.rb
piggybak-0.5.3 lib/acts_as_changer.rb
piggybak-0.5.2 lib/acts_as_changer.rb