module ActionPolicy::Policy::FailureReasons::ResultFailureReasons

Extend ExecutionResult with `reasons` method

Attributes

details[RW]

Public Instance Methods

all_details() click to toggle source

Returns all the details merged together

# File lib/action_policy/policy/reasons.rb, line 86
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() click to toggle source
# File lib/action_policy/policy/reasons.rb, line 81
def clear_details
  @details = nil
end
inspect() click to toggle source

Add reasons to inspect

Calls superclass method
# File lib/action_policy/policy/reasons.rb, line 105
def inspect
  super.then do |str|
    next str if reasons.empty?
    str.sub(/>$/, " (reasons: #{reasons.details})")
  end
end
reasons() click to toggle source
# File lib/action_policy/policy/reasons.rb, line 75
def reasons
  @reasons ||= FailureReasons.new
end