Module: ActionPolicy::Policy::ResultFailureReasons

Defined in:
lib/action_policy/policy/reasons.rb

Overview

Extend ExecutionResult with ‘reasons` method

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#detailsObject

Returns the value of attribute details.



79
80
81
# File 'lib/action_policy/policy/reasons.rb', line 79

def details
  @details
end

Instance Method Details

#all_detailsObject

Returns all the details merged together



86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# 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_detailsObject



81
82
83
# File 'lib/action_policy/policy/reasons.rb', line 81

def clear_details
  @details = nil
end

#inspectObject

Add reasons to inspect



105
106
107
108
109
110
# 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

#reasonsObject



75
76
77
# File 'lib/action_policy/policy/reasons.rb', line 75

def reasons
  @reasons ||= FailureReasons.new
end