Class: Puppet::Pops::Validation::SeverityProducer
- Defined in:
- lib/puppet/pops/validation.rb
Overview
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)`.
Direct Known Subclasses
Constant Summary collapse
- @@severity_hash =
{:ignore => true, :warning => true, :error => true, :deprecation => true }
Instance Method Summary collapse
- #[](issue) ⇒ Object
-
#[]=(issue, level) ⇒ Object
Override a default severity with the given severity level.
-
#assert_issue(issue) ⇒ Object
private
Checks if the given issue is valid.
-
#assert_severity(level) ⇒ Object
private
Checks if the given severity level is valid.
-
#initialize(default_severity = :error) ⇒ SeverityProducer
constructor
Creates a new instance where all issues are diagnosed as :error unless overridden.
-
#severity(issue) ⇒ Symbol
Returns the severity of the given issue.
-
#should_report?(issue) ⇒ Boolean
Returns ‘true` if the issue should be reported or not.
Constructor Details
#initialize(default_severity = :error) ⇒ SeverityProducer
Creates a new instance where all issues are diagnosed as :error unless overridden.
99 100 101 102 |
# File 'lib/puppet/pops/validation.rb', line 99 def initialize(default_severity = :error) # If diagnose is not set, the default is returned by the block @severities = Hash.new default_severity end |
Instance Method Details
#[](issue) ⇒ Object
116 117 118 |
# File 'lib/puppet/pops/validation.rb', line 116 def [] issue severity issue end |
#[]=(issue, level) ⇒ Object
Override a default severity with the given severity level.
126 127 128 129 130 131 |
# File 'lib/puppet/pops/validation.rb', line 126 def []=(issue, level) raise Puppet::DevError.new("Attempt to set validation severity for something that is not an Issue. (Got #{issue.class})") unless issue.is_a? Puppet::Pops::Issues::Issue raise Puppet::DevError.new("Illegal severity level: #{option}") unless @@severity_hash[level] raise Puppet::DevError.new("Attempt to demote the hard issue '#{issue.issue_code}' to #{level}") unless issue.demotable? || level == :error @severities[issue] = level end |
#assert_issue(issue) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Checks if the given issue is valid.
146 147 148 |
# File 'lib/puppet/pops/validation.rb', line 146 def assert_issue issue raise Puppet::DevError.new("Attempt to get validation severity for something that is not an Issue. (Got #{issue.class})") unless issue.is_a? Puppet::Pops::Issues::Issue end |
#assert_severity(level) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Checks if the given severity level is valid.
153 154 155 |
# File 'lib/puppet/pops/validation.rb', line 153 def assert_severity level raise Puppet::DevError.new("Illegal severity level: #{option}") unless @@severity_hash[level] end |
#severity(issue) ⇒ Symbol
Returns the severity of the given issue.
108 109 110 111 |
# File 'lib/puppet/pops/validation.rb', line 108 def severity(issue) assert_issue(issue) @severities[issue] end |
#should_report?(issue) ⇒ Boolean
Returns ‘true` if the issue should be reported or not.
138 139 140 141 |
# File 'lib/puppet/pops/validation.rb', line 138 def should_report? issue diagnose = @severities[issue] diagnose == :error || diagnose == :warning || diagnose == :deprecation end |