Sha256: 96eff31e691b741529f052f7e123edd9b84ddb30c00dd147893691d6836d94a7

Contents?: true

Size: 1.33 KB

Versions: 3

Compression:

Stored size: 1.33 KB

Contents

require 'active_support/concern'
require 'active_model/dirty'

module Ripple
  module AttributeMethods
    module Dirty
      extend ActiveSupport::Concern
      include ActiveModel::Dirty

      module ClassMethods
        # @private
        def instantiate(robject)
          super(robject).tap do |o|
            o.changed_attributes.clear
          end
        end
      end

      # @private
      def really_save(*args)
        if result = super
          @previously_changed = changes
          changed_attributes.clear
        end
        result
      end

      # @private
      def reload
        super.tap do
          changed_attributes.clear
        end
      end

      # @private
      def initialize(*args)
        super
        changed_attributes.clear
      end

      # Determines if the document has any chnages.
      # @return [Boolean] true if this document, or any of its embedded
      # documents at any level, have changed.
      def changed?
        super || self.class.embedded_associations.any? do |association|
          send(association.name).has_changed_documents?
        end
      end

      private
      def attribute=(attr_name, value)
        if self.class.properties.include?(attr_name.to_sym) && @attributes[attr_name] != value
          attribute_will_change!(attr_name)
        end
        super
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 3 rubygems

Version Path
wyngle-ripple-0.1.0 lib/ripple/attribute_methods/dirty.rb
better-ripple-1.0.0 lib/ripple/attribute_methods/dirty.rb
ripple-1.0.0.beta2 lib/ripple/attribute_methods/dirty.rb