Module: ActsAsApprovable::Model::DestroyInstanceMethods

Defined in:
lib/acts_as_approvable/model/destroy_instance_methods.rb

Overview

Instance methods that apply to the ‘:destroy` event specifically.

Instance Method Summary collapse

Instance Method Details

#destroyObject

Add a ‘:destrory` approval event to the queue if approvals are enabled, otherwise destroy the record.



24
25
26
# File 'lib/acts_as_approvable/model/destroy_instance_methods.rb', line 24

def destroy
  approvable_destroy? ? request_destruction : super
end

#destroy_approvals(all = true) ⇒ Approval

Retrieve approval records for the destruction event.

Parameters:

  • all (Boolean) (defaults to: true)

    toggle for returning all or pending approvals

Returns:



11
12
13
# File 'lib/acts_as_approvable/model/destroy_instance_methods.rb', line 11

def destroy_approvals(all = true)
  all ? approvals.find_all_by_event('destroy') : approvals.find_all_by_event_and_state('destroy', 0)
end

#pending_destruction?Boolean

Returns true if there are any pending ‘:destroy` event approvals

Returns:

  • (Boolean)


17
18
19
# File 'lib/acts_as_approvable/model/destroy_instance_methods.rb', line 17

def pending_destruction?
  not destroy_approvals(false).empty?
end