Module: Protective::InstanceMethods
- Defined in:
- lib/protective.rb
Instance Method Summary collapse
-
#destruction_allowed? ⇒ Boolean
Returns true if this record may be destroyed or adds possible error messages to the #errors object otherwise.
-
#protected? ⇒ Boolean
Returns true if this record cannot be destroyed.
Instance Method Details
#destruction_allowed? ⇒ Boolean
Returns true if this record may be destroyed or adds possible error messages to the #errors object otherwise.
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, | allowed = protect_method_allows_destruction(method) errors.add(:base, ) if !allowed && allowed end throw(:abort) if !success && ActiveRecord::VERSION::MAJOR >= 5 success end |
#protected? ⇒ Boolean
Returns true if this record cannot be destroyed.
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 |