Module: Disabling

Extended by:
ActiveSupport::Concern
Defined in:
app/models/concerns/disabling.rb

Overview

The disposable module is a soft-delete helper that:

* adds `disable!` method that set a `disabled_at` attribute and then _buries_ the object
* adds a `bury!`  hook method that allows further modification when disabling
* aliases `destroy!` and `destroy` to `disable!`, but still keeps `delete` and friends

Instance Method Summary collapse

Instance Method Details

#bury!Object

override to perform additional post-disable actions



27
28
# File 'app/models/concerns/disabling.rb', line 27

def bury!
end

#disable!Object Also known as: destroy!, destroy



10
11
12
13
14
15
# File 'app/models/concerns/disabling.rb', line 10

def disable!
  transaction do
    update_attribute :disabled_at, Time.current
    bury!
  end
end

#disabled?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'app/models/concerns/disabling.rb', line 17

def disabled?
  disabled_at.present?
end

#enabled?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'app/models/concerns/disabling.rb', line 21

def enabled?
  !disabled?
end

#ensure_enabled!Object



30
31
32
# File 'app/models/concerns/disabling.rb', line 30

def ensure_enabled!
  raise Mumuki::Domain::DisabledError if disabled?
end