Class: ActionPolicy::Policy::FailureReasons
- Inherits:
-
Object
- Object
- ActionPolicy::Policy::FailureReasons
- Defined in:
- lib/action_policy/policy/reasons.rb
Overview
Failures reasons store
Instance Attribute Summary collapse
-
#reasons ⇒ Object
readonly
Returns the value of attribute reasons.
Instance Method Summary collapse
- #add(policy_or_class, rule, details = nil) ⇒ Object
-
#details ⇒ Object
Return Hash of the form: { policy_identifier => [rules, …] }.
- #empty? ⇒ Boolean
-
#initialize ⇒ FailureReasons
constructor
A new instance of FailureReasons.
- #merge(other) ⇒ Object
- #present? ⇒ Boolean
Constructor Details
#initialize ⇒ FailureReasons
Returns a new instance of FailureReasons.
11 12 13 |
# File 'lib/action_policy/policy/reasons.rb', line 11 def initialize @reasons = {} end |
Instance Attribute Details
#reasons ⇒ Object (readonly)
Returns the value of attribute reasons.
9 10 11 |
# File 'lib/action_policy/policy/reasons.rb', line 9 def reasons @reasons end |
Instance Method Details
#add(policy_or_class, rule, details = nil) ⇒ Object
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/action_policy/policy/reasons.rb', line 15 def add(policy_or_class, rule, details = nil) policy_class = policy_or_class.is_a?(Module) ? policy_or_class : policy_or_class.class reasons[policy_class] ||= [] if details.nil? add_non_detailed_reason reasons[policy_class], rule else add_detailed_reason reasons[policy_class], with_details(rule, details) end end |
#details ⇒ Object
Return Hash of the form:
{ policy_identifier => [rules, ...] }
28 |
# File 'lib/action_policy/policy/reasons.rb', line 28 def details() = reasons.transform_keys(&:identifier) |
#empty? ⇒ Boolean
30 |
# File 'lib/action_policy/policy/reasons.rb', line 30 def empty?() = reasons.empty? |
#merge(other) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/action_policy/policy/reasons.rb', line 34 def merge(other) other.reasons.each do |policy_class, rules| reasons[policy_class] ||= [] rules.each do |rule| if rule.is_a?(::Hash) add_detailed_reason(reasons[policy_class], rule) else add_non_detailed_reason(reasons[policy_class], rule) end end end end |
#present? ⇒ Boolean
32 |
# File 'lib/action_policy/policy/reasons.rb', line 32 def present?() = !empty? |