Sha256: 2da54454a9482fd1b14fb53e80c4925f7ce4d572df5ab827d547fe5b88c8d04a

Contents?: true

Size: 1.08 KB

Versions: 21

Compression:

Stored size: 1.08 KB

Contents

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

      # Attempts to +save+ the record and clears changed attributes if successful.
      def save(*) #:nodoc:
        if status = super
          @previously_changed = changes
          @changed_attributes.clear
        end
        status
      end

      # Attempts to <tt>save!</tt> the record and clears changed attributes if successful.
      def save!(*) #:nodoc:
        super.tap do
          @previously_changed = changes
          @changed_attributes.clear
        end
      end

      # <tt>reload</tt> the record and clears changed attributes.
      def reload
        super.tap do
          @previously_changed.try :clear
          @changed_attributes.try :clear
        end
      end

      def write_attribute(name, value)
        name = name.to_s
        old = read_attribute(name)

        super

        unless attribute_changed?(name) || old == read_attribute(name)
          changed_attributes[name] = old
        end
      end
    end
  end
end

Version data entries

21 entries across 21 versions & 2 rubygems

Version Path
gotime-cassandra_object-4.11.3 lib/cassandra_object/attribute_methods/dirty.rb
gotime-cassandra_object-4.11.2 lib/cassandra_object/attribute_methods/dirty.rb
gotime-cassandra_object-4.11.1 lib/cassandra_object/attribute_methods/dirty.rb
gotime-cassandra_object-4.11.0 lib/cassandra_object/attribute_methods/dirty.rb
gotime-cassandra_object-4.10.5 lib/cassandra_object/attribute_methods/dirty.rb
gotime-cassandra_object-4.10.4 lib/cassandra_object/attribute_methods/dirty.rb
gotime-cassandra_object-4.10.3 lib/cassandra_object/attribute_methods/dirty.rb
gotime-cassandra_object-4.10.2 lib/cassandra_object/attribute_methods/dirty.rb
gotime-cassandra_object-4.10.1 lib/cassandra_object/attribute_methods/dirty.rb
cassandra_object_rails-0.0.1 lib/cassandra_object/attribute_methods/dirty.rb
gotime-cassandra_object-4.10.0 lib/cassandra_object/attribute_methods/dirty.rb
gotime-cassandra_object-4.9.2 lib/cassandra_object/attribute_methods/dirty.rb
gotime-cassandra_object-4.9.1 lib/cassandra_object/attribute_methods/dirty.rb
gotime-cassandra_object-4.9.0 lib/cassandra_object/attribute_methods/dirty.rb
gotime-cassandra_object-4.8.1 lib/cassandra_object/attribute_methods/dirty.rb
gotime-cassandra_object-4.8.0 lib/cassandra_object/attribute_methods/dirty.rb
gotime-cassandra_object-4.7.3 lib/cassandra_object/attribute_methods/dirty.rb
gotime-cassandra_object-4.7.2 lib/cassandra_object/attribute_methods/dirty.rb
gotime-cassandra_object-4.7.1 lib/cassandra_object/attribute_methods/dirty.rb
gotime-cassandra_object-4.7.0 lib/cassandra_object/attribute_methods/dirty.rb