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-2.3.9 lib/cassandra_object/dirty.rb
sessionm-cassandra_object-2.3.8 lib/cassandra_object/dirty.rb
sessionm-cassandra_object-2.3.6 lib/cassandra_object/dirty.rb
sessionm-cassandra_object-2.3.5 lib/cassandra_object/dirty.rb
sessionm-cassandra_object-2.3.4 lib/cassandra_object/dirty.rb
sessionm-cassandra_object-2.3.3 lib/cassandra_object/dirty.rb
sessionm-cassandra_object-2.3.2 lib/cassandra_object/dirty.rb
sessionm-cassandra_object-2.3.1 lib/cassandra_object/dirty.rb
sessionm-cassandra_object-2.3.0 lib/cassandra_object/dirty.rb
sessionm-cassandra_object-2.2.55 lib/cassandra_object/dirty.rb
sessionm-cassandra_object-2.2.54 lib/cassandra_object/dirty.rb
sessionm-cassandra_object-2.2.53 lib/cassandra_object/dirty.rb
sessionm-cassandra_object-2.2.52 lib/cassandra_object/dirty.rb
sessionm-cassandra_object-2.2.51 lib/cassandra_object/dirty.rb
sessionm-cassandra_object-2.2.50 lib/cassandra_object/dirty.rb
sessionm-cassandra_object-2.2.49 lib/cassandra_object/dirty.rb
sessionm-cassandra_object-2.2.48 lib/cassandra_object/dirty.rb
sessionm-cassandra_object-2.2.47 lib/cassandra_object/dirty.rb
sessionm-cassandra_object-2.2.46 lib/cassandra_object/dirty.rb
sessionm-cassandra_object-2.2.45 lib/cassandra_object/dirty.rb