Module: StatusAssignable
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/status_assignable.rb,
lib/status_assignable/railtie.rb,
lib/status_assignable/version.rb,
lib/status_assignable/association.rb,
lib/status_assignable/active_record.rb
Overview
Allows for soft deletion of records. Include this module in your model to enable soft deletion. e.g:
class User < ApplicationRecord
include StatusAssignable
end
This requires a status column with type integer to be present in the model’s table.
Defined Under Namespace
Modules: ActiveRecord, Association Classes: Railtie
Constant Summary collapse
- DEFAULT_STATUSES =
{ deleted: 0, active: 1, inactive: 2 }.freeze
- VERSION =
'0.1.4'
Class Method Summary collapse
-
.[](status_dictionary) ⇒ StatusAssignable
Allows adding custom statuses to the model’s status enum.
- .clear_dictionary ⇒ Object
- .status_dictionary ⇒ Object
Class Method Details
.[](status_dictionary) ⇒ StatusAssignable
Allows adding custom statuses to the model’s status enum.
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/status_assignable.rb', line 30 def self.[](status_dictionary) resulting_statuses = DEFAULT_STATUSES.merge(status_dictionary) raise ArgumentError, "Default statuses overridden. Don't do this." unless resulting_statuses >= DEFAULT_STATUSES unless resulting_statuses.values.uniq.length == resulting_statuses.values.length raise ArgumentError, 'Status values must be unique.' end @status_dictionary = resulting_statuses self end |
.clear_dictionary ⇒ Object
23 24 25 |
# File 'lib/status_assignable.rb', line 23 def self.clear_dictionary @status_dictionary = nil end |
.status_dictionary ⇒ Object
19 20 21 |
# File 'lib/status_assignable.rb', line 19 def self.status_dictionary @status_dictionary || { deleted: 0, active: 1, inactive: 2 } end |