Sha256: 3df4c5a516d67fe42121a422acade3b5f8af8853ae362c1a4d6744591e336a37

Contents?: true

Size: 1.34 KB

Versions: 1

Compression:

Stored size: 1.34 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(attrs={})
        super(attrs)
        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

1 entries across 1 versions & 1 rubygems

Version Path
ripple-1.0.0.beta lib/ripple/attribute_methods/dirty.rb