Module: Disposable::Twin::Persisted

Defined in:
lib/disposable/twin/persisted.rb

Overview

Keeps the #persisted? property synced with the model’s.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(includer) ⇒ Object



3
4
5
# File 'lib/disposable/twin/persisted.rb', line 3

def self.included(includer)
  includer.send(:property, :persisted?, writeable: false)
end

Instance Method Details

#created?Boolean

Returns:

  • (Boolean)


13
14
15
16
# File 'lib/disposable/twin/persisted.rb', line 13

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

#save!Object



7
8
9
10
11
# File 'lib/disposable/twin/persisted.rb', line 7

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