class Puppet::Pops::Validation::SeverityProducer
Decides on the severity of a given issue. The produced severity is one of `:error`, `:warning`, or `:ignore`. By default, a severity of `:error` is produced for all issues. To configure the severity of an issue call `#severity=(issue, level)`.
@return [Symbol] a symbol representing the severity `:error`, `:warning`, or `:ignore`
@api public
Constants
- SEVERITIES
Public Class Methods
Creates a new instance where all issues are diagnosed as :error unless overridden. @param [Symbol] specifies default severity if :error is not wanted as the default @api public
# File lib/puppet/pops/validation.rb 101 def initialize(default_severity = :error) 102 # If diagnose is not set, the default is returned by the block 103 @severities = Hash.new default_severity 104 end
Public Instance Methods
@see {#severity} @api public
# File lib/puppet/pops/validation.rb 118 def [] issue 119 severity issue 120 end
Override a default severity with the given severity level.
@param issue [Issues::Issue] the issue for which to set severity @param level [Symbol] the severity level (:error, :warning, or :ignore). @api public
# File lib/puppet/pops/validation.rb 128 def []=(issue, level) 129 unless issue.is_a? Issues::Issue 130 raise Puppet::DevError.new(_("Attempt to set validation severity for something that is not an Issue. (Got %{issue})") % { issue: issue.class }) 131 end 132 unless SEVERITIES[level] 133 raise Puppet::DevError.new(_("Illegal severity level: %{level} for '%{issue_code}'") % { issue_code: issue.issue_code, level: level }) 134 end 135 unless issue.demotable? || level == :error 136 raise Puppet::DevError.new(_("Attempt to demote the hard issue '%{issue_code}' to %{level}") % { issue_code: issue.issue_code, level: level }) 137 end 138 @severities[issue] = level 139 end
Checks if the given issue is valid. @api private
# File lib/puppet/pops/validation.rb 154 def assert_issue issue 155 unless issue.is_a? Issues::Issue 156 raise Puppet::DevError.new(_("Attempt to get validation severity for something that is not an Issue. (Got %{issue})") % { issue: issue.class }) 157 end 158 end
Returns the severity of the given issue. @return [Symbol] severity level :error, :warning, or :ignore @api public
# File lib/puppet/pops/validation.rb 110 def severity(issue) 111 assert_issue(issue) 112 @severities[issue] 113 end
Returns `true` if the issue should be reported or not. @return [Boolean] this implementation returns true for errors and warnings
@api public
# File lib/puppet/pops/validation.rb 146 def should_report? issue 147 diagnose = @severities[issue] 148 diagnose == :error || diagnose == :warning || diagnose == :deprecation 149 end