Sha256: eeec5d7850abefc4a316f5853936ab75c60f9a9b3491eb88be7b0859470f770e

Contents?: true

Size: 599 Bytes

Versions: 40

Compression:

Stored size: 599 Bytes

Contents

# Keeps the #persisted? property synced with the model's.
module Disposable::Twin::Persisted
  def self.included(includer)
    includer.send(:property, :persisted?, writeable: false)
  end

  def save!(*)
    super.tap do
      send "persisted?=", model.persisted?
    end
  end

  def created?
    # when the persisted field got flipped, this means creation!
    changed?(:persisted?)
  end

  # DISCUSS: i did not add #updated? on purpose. while #created's semantic is clear, #updated is confusing.
  # does it include change, etc. i leave this up to the user until we have a clear definition.
end

Version data entries

40 entries across 40 versions & 1 rubygems

Version Path
disposable-0.6.3 lib/disposable/twin/persisted.rb
disposable-0.6.2 lib/disposable/twin/persisted.rb
disposable-0.6.1 lib/disposable/twin/persisted.rb
disposable-0.6.0 lib/disposable/twin/persisted.rb
disposable-0.5.0 lib/disposable/twin/persisted.rb
disposable-0.4.7 lib/disposable/twin/persisted.rb
disposable-0.4.6 lib/disposable/twin/persisted.rb
disposable-0.4.5 lib/disposable/twin/persisted.rb
disposable-0.4.4 lib/disposable/twin/persisted.rb
disposable-0.4.3 lib/disposable/twin/persisted.rb
disposable-0.4.2 lib/disposable/twin/persisted.rb
disposable-0.4.1 lib/disposable/twin/persisted.rb
disposable-0.4.0 lib/disposable/twin/persisted.rb
disposable-0.3.2 lib/disposable/twin/persisted.rb
disposable-0.3.1 lib/disposable/twin/persisted.rb
disposable-0.3.0 lib/disposable/twin/persisted.rb
disposable-0.2.6 lib/disposable/twin/persisted.rb
disposable-0.2.5 lib/disposable/twin/persisted.rb
disposable-0.2.4 lib/disposable/twin/persisted.rb
disposable-0.2.3 lib/disposable/twin/persisted.rb