Sha256: eed9f9c1900faf1b6751c15acfb9a5c7a5a681955d135fc8566db878cf315ce1

Contents?: true

Size: 1.03 KB

Versions: 13

Compression:

Stored size: 1.03 KB

Contents

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

    module InstanceMethods
      def initialize(*)
        super
        if new_record?
          # never register initial id assignment as a change
          @changed_attributes.delete('id')
        else
          @previously_changed = {}
          @changed_attributes.clear if @changed_attributes
        end
      end

      def initialize_copy(*)
        super.tap do
          @previously_changed = {}
          @changed_attributes = {}
        end
      end

      def reload
        super.tap do
          @previously_changed = {}
          @changed_attributes = {}
        end
      end

      def save(*)
        super.tap do
          @previously_changed = changes
          @changed_attributes.clear if @changed_attributes
        end
      end

      def write_attribute(name, value)
        name    = name.to_s
        current = read_attribute(name)
        attribute_will_change!(name) if current != value
        super
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
toystore-0.8.3 lib/toy/dirty.rb
toystore-0.8.2 lib/toy/dirty.rb
toystore-0.8.1 lib/toy/dirty.rb
toystore-0.8.0 lib/toy/dirty.rb
toystore-0.7.0 lib/toy/dirty.rb
toystore-0.6.6 lib/toy/dirty.rb
toystore-0.6.5 lib/toy/dirty.rb
toystore-0.6.4 lib/toy/dirty.rb
toystore-0.6.3 lib/toy/dirty.rb
toystore-0.6.2 lib/toy/dirty.rb
toystore-0.6.1 lib/toy/dirty.rb
toystore-0.6 lib/toy/dirty.rb
toystore-0.5 lib/toy/dirty.rb