Module: ActionPolicy::Policy::ResultFailureReasons
- Defined in:
- lib/action_policy/policy/reasons.rb
Overview
Extend ExecutionResult with ‘reasons` method
Instance Attribute Summary collapse
-
#details ⇒ Object
Returns the value of attribute details.
Instance Method Summary collapse
-
#all_details ⇒ Object
Returns all the details merged together.
- #clear_details ⇒ Object
-
#inspect ⇒ Object
Add reasons to inspect.
- #reasons ⇒ Object
Instance Attribute Details
#details ⇒ Object
Returns the value of attribute details.
81 82 83 |
# File 'lib/action_policy/policy/reasons.rb', line 81 def details @details end |
Instance Method Details
#all_details ⇒ Object
Returns all the details merged together
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/action_policy/policy/reasons.rb', line 88 def all_details return @all_details if defined?(@all_details) @all_details = {}.tap do |all| next unless defined?(@reasons) reasons.reasons.each_value do |rules| detailed_reasons = rules.last next unless detailed_reasons.is_a?(Hash) detailed_reasons.each_value do |details| all.merge!(details) end end end end |
#clear_details ⇒ Object
83 84 85 |
# File 'lib/action_policy/policy/reasons.rb', line 83 def clear_details @details = nil end |
#inspect ⇒ Object
Add reasons to inspect
107 108 109 110 111 112 |
# File 'lib/action_policy/policy/reasons.rb', line 107 def inspect super.then do |str| next str if reasons.empty? str.sub(/>$/, " (reasons: #{reasons.details})") end end |
#reasons ⇒ Object
77 78 79 |
# File 'lib/action_policy/policy/reasons.rb', line 77 def reasons @reasons ||= FailureReasons.new end |