Module: Koi::Model::Archivable
- Extended by:
- ActiveSupport::Concern
- Included in:
- Admin::User
- Defined in:
- app/models/concerns/koi/model/archivable.rb
Instance Method Summary collapse
-
#archive ⇒ Object
Mark a record as archived.
-
#archive! ⇒ Object
Archive a record immediately, without validation.
-
#archived ⇒ Object
Returns true iff the record has been archived.
-
#archived=(archived) ⇒ Object
Update archived status based on given boolean value.
-
#restore ⇒ Object
Mark a record as no longer archived.
-
#restore! ⇒ Object
Restore a record immediately, without validation.
Instance Method Details
#archive ⇒ Object
Mark a record as archived. It will no longer appear in default queries.
33 34 35 |
# File 'app/models/concerns/koi/model/archivable.rb', line 33 def archive self.archived_at = Time.current end |
#archive! ⇒ Object
Archive a record immediately, without validation.
38 39 40 41 |
# File 'app/models/concerns/koi/model/archivable.rb', line 38 def archive! archive save!(validate: false) end |
#archived ⇒ Object
Returns true iff the record has been archived.
19 20 21 |
# File 'app/models/concerns/koi/model/archivable.rb', line 19 def archived archived_at.present? end |
#archived=(archived) ⇒ Object
Update archived status based on given boolean value.
24 25 26 27 28 29 30 |
# File 'app/models/concerns/koi/model/archivable.rb', line 24 def archived=(archived) if ActiveRecord::Type::Boolean.new.cast(archived) archive else restore end end |
#restore ⇒ Object
Mark a record as no longer archived. It will appear in default queries.
44 45 46 |
# File 'app/models/concerns/koi/model/archivable.rb', line 44 def restore self.archived_at = nil end |
#restore! ⇒ Object
Restore a record immediately, without validation.
49 50 51 52 |
# File 'app/models/concerns/koi/model/archivable.rb', line 49 def restore! restore save!(validate: false) end |