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

new(default_severity = :error) click to toggle source

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
100 def initialize(default_severity = :error)
101   # If diagnose is not set, the default is returned by the block
102   @severities = Hash.new default_severity
103 end

Public Instance Methods

[](issue) click to toggle source

@see {#severity} @api public

    # File lib/puppet/pops/validation.rb
117 def [] issue
118   severity issue
119 end
[]=(issue, level) click to toggle source

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
127 def []=(issue, level)
128   unless issue.is_a? Issues::Issue
129     raise Puppet::DevError.new(_("Attempt to set validation severity for something that is not an Issue. (Got %{issue})") % { issue: issue.class })
130   end
131   unless SEVERITIES[level]
132     raise Puppet::DevError.new(_("Illegal severity level: %{level} for '%{issue_code}'") % { issue_code: issue.issue_code, level: level })
133   end
134   unless issue.demotable? || level == :error
135     raise Puppet::DevError.new(_("Attempt to demote the hard issue '%{issue_code}' to %{level}") % { issue_code: issue.issue_code, level: level })
136   end
137   @severities[issue] = level
138 end
assert_issue(issue) click to toggle source

Checks if the given issue is valid. @api private

    # File lib/puppet/pops/validation.rb
153 def assert_issue issue
154   unless issue.is_a? Issues::Issue
155     raise Puppet::DevError.new(_("Attempt to get validation severity for something that is not an Issue. (Got %{issue})") % { issue: issue.class })
156   end
157 end
severity(issue) click to toggle source

Returns the severity of the given issue. @return [Symbol] severity level :error, :warning, or :ignore @api public

    # File lib/puppet/pops/validation.rb
109 def severity(issue)
110   assert_issue(issue)
111   @severities[issue]
112 end
should_report?(issue) click to toggle source

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
145 def should_report? issue
146   diagnose = @severities[issue]
147   diagnose == :error || diagnose == :warning || diagnose == :deprecation
148 end