Sha256: 23b404931fca45535392e680523ed0941f9706d0cf8ab389286c076e1966d44c

Contents?: true

Size: 758 Bytes

Versions: 7

Compression:

Stored size: 758 Bytes

Contents

module MotionPrime
  module ModelDirtyMixin
    extend ::MotionSupport::Concern

    def self.included(base)
      base.class_attribute :_changed_attributes
    end

    def track_changed_attributes(&block)
      @_changed_attributes ||= {}
      old_attrs = self.info.clone
      result = block.call
      new_attrs = self.info.clone
      new_attrs.each do |key, value|
        if value != old_attrs[key] && ! @_changed_attributes.has_key?(key.to_s)
          @_changed_attributes[key.to_s] = old_attrs[key]
        end
      end
      result
    end

    def has_changed?(key = nil)
      @_changed_attributes ||= {}
      if key
        @_changed_attributes.has_key?(key.to_s)
      else
        @_changed_attributes.present?
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
motion-prime-0.5.6 motion-prime/models/_dirty_mixin.rb
motion-prime-0.5.5 motion-prime/models/_dirty_mixin.rb
motion-prime-0.5.4 motion-prime/models/_dirty_mixin.rb
motion-prime-0.5.3 motion-prime/models/_dirty_mixin.rb
motion-prime-0.5.2 motion-prime/models/_dirty_mixin.rb
motion-prime-0.5.1 motion-prime/models/_dirty_mixin.rb
motion-prime-0.5.0 motion-prime/models/_dirty_mixin.rb