Sha256: 96232fcb0ad065cc164f477e0aa7dccaff0a3674dc2247b686563d0cdf45f028

Contents?: true

Size: 1013 Bytes

Versions: 80

Compression:

Stored size: 1013 Bytes

Contents

module CassandraObject
  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
        @original_attribute_values = nil
      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
        @original_attribute_values = nil
      end
    end

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

      # handle orig -> new -> orig
      if attribute_changed?(name)
        orig = changed_attributes[name]
        changed_attributes.delete(name) if orig == value
      else
        old = read_attribute(name)
        changed_attributes[name] = old if old != value
      end
      super
    end
  end
end

Version data entries

80 entries across 80 versions & 1 rubygems

Version Path
sessionm-cassandra_object-4.0.13 lib/cassandra_object/dirty.rb
sessionm-cassandra_object-4.0.12 lib/cassandra_object/dirty.rb
sessionm-cassandra_object-4.0.11 lib/cassandra_object/dirty.rb
sessionm-cassandra_object-4.0.10 lib/cassandra_object/dirty.rb
sessionm-cassandra_object-4.0.9 lib/cassandra_object/dirty.rb
sessionm-cassandra_object-2.7.3 lib/cassandra_object/dirty.rb
sessionm-cassandra_object-2.7.2 lib/cassandra_object/dirty.rb
sessionm-cassandra_object-4.0.8 lib/cassandra_object/dirty.rb
sessionm-cassandra_object-4.0.7 lib/cassandra_object/dirty.rb
sessionm-cassandra_object-4.0.6 lib/cassandra_object/dirty.rb
sessionm-cassandra_object-4.0.5 lib/cassandra_object/dirty.rb
sessionm-cassandra_object-4.0.4 lib/cassandra_object/dirty.rb
sessionm-cassandra_object-4.0.3 lib/cassandra_object/dirty.rb
sessionm-cassandra_object-4.0.2 lib/cassandra_object/dirty.rb
sessionm-cassandra_object-4.0.1 lib/cassandra_object/dirty.rb
sessionm-cassandra_object-4.0.0 lib/cassandra_object/dirty.rb
sessionm-cassandra_object-2.7.1 lib/cassandra_object/dirty.rb
sessionm-cassandra_object-2.7.0 lib/cassandra_object/dirty.rb
sessionm-cassandra_object-2.6.1 lib/cassandra_object/dirty.rb
sessionm-cassandra_object-2.6.0 lib/cassandra_object/dirty.rb