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
# File 'lib/protective.rb', line 38

def destruction_allowed?
  protect_if_methods.all? do |method, message|
    unless allowed = protect_method_allows_destruction(method)
      errors.add(:base, message) if message
    end
    allowed
  end
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