Module: Protective::InstanceMethods

Defined in:
lib/protective.rb

Instance Method Summary collapse

Instance Method Details

#destruction_allowed?Boolean

Returns true if this record may be destroyed or adds possible error messages to the #errors object otherwise.

Returns:

  • (Boolean)


38
39
40
41
42
43
44
45
46
47
# File 'lib/protective.rb', line 38

def destruction_allowed?
  success = protect_if_methods.all? do |method, message|
    allowed = protect_method_allows_destruction(method)
    errors.add(:base, message) if !allowed && message
    allowed
  end

  throw(:abort) if !success && ActiveRecord::VERSION::MAJOR >= 5
  success
end

#protected?Boolean

Returns true if this record cannot be destroyed.

Returns:

  • (Boolean)


30
31
32
33
34
# File 'lib/protective.rb', line 30

def protected?
  protect_if_methods.keys.any? do |method|
    !protect_method_allows_destruction(method)
  end
end