Sha256: e2f9f061e0f3045053119e795065f349be38adb17e8c98295f29d4edd9337a57

Contents?: true

Size: 756 Bytes

Versions: 12

Compression:

Stored size: 756 Bytes

Contents

module MongoModel
  module Attributes
    module Dirty
      def []=(key, value)
        attr = key.to_sym
        
        # The attribute already has an unsaved change.
        if changed.include?(attr)
          old = changed[attr]
          changed.delete(attr) if value == old
        else
          old = clone_attribute_value(attr)
          changed[attr] = old unless value == old
        end
        
        super
      end
      
      def changed
        @changed ||= {}.with_indifferent_access
      end
      
    private
      def clone_attribute_value(attribute_name)
        value = self[attribute_name.to_sym]
        value.duplicable? ? value.clone : value
      rescue TypeError, NoMethodError
        value
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
mongomodel-0.2.17 lib/mongomodel/attributes/dirty.rb
mongomodel-0.2.16 lib/mongomodel/attributes/dirty.rb
mongomodel-0.2.15 lib/mongomodel/attributes/dirty.rb
mongomodel-0.2.14 lib/mongomodel/attributes/dirty.rb
mongomodel-0.2.13 lib/mongomodel/attributes/dirty.rb
mongomodel-0.2.12 lib/mongomodel/attributes/dirty.rb
mongomodel-0.2.11 lib/mongomodel/attributes/dirty.rb
mongomodel-0.2.10 lib/mongomodel/attributes/dirty.rb
mongomodel-0.2.9 lib/mongomodel/attributes/dirty.rb
mongomodel-0.2.8 lib/mongomodel/attributes/dirty.rb
mongomodel-0.2.7 lib/mongomodel/attributes/dirty.rb
mongomodel-0.2.6 lib/mongomodel/attributes/dirty.rb