Sha256: a89279fa11defeb5f7b4a658962260be0f94169c6b52511cc6a29436cca66366

Contents?: true

Size: 584 Bytes

Versions: 9

Compression:

Stored size: 584 Bytes

Contents

module SuperModel
  module Dirty
    extend ActiveSupport::Concern
    include ActiveModel::Dirty

    included do
      %w( create update ).each do |method|
        class_eval(<<-EOS, __FILE__, __LINE__ + 1)
          def #{method}_with_dirty(*args, &block)
            result = #{method}_without_dirty(*args, &block)
            save_previous_changes
            result
          end
        EOS
        alias_method_chain(method, :dirty)
      end
    end
        
    def save_previous_changes
      @previously_changed = changes
      @changed_attributes.clear
    end
  end
end

Version data entries

9 entries across 9 versions & 3 rubygems

Version Path
worsemodel-0.2.0 lib/supermodel/dirty.rb
worsemodel-0.1.9 lib/supermodel/dirty.rb
worsemodel-0.1.8 lib/supermodel/dirty.rb
worsemodel-0.1.7 lib/supermodel/dirty.rb
supermodel-0.1.6 lib/supermodel/dirty.rb
supermodel-0.1.5 lib/supermodel/dirty.rb
csun-student-affairs-supermodel-0.1.5 lib/supermodel/dirty.rb
supermodel-0.1.4 lib/supermodel/dirty.rb
supermodel-0.1.3 lib/supermodel/dirty.rb