Class: Puppet::Pops::Validation::DiagnosticProducer
- Defined in:
- lib/puppet/pops/validation.rb
Overview
A producer of diagnostics. An producer of diagnostics is given each issue occurrence as they are found by a diagnostician/validator. It then produces a Diagnostic, which it passes on to a configured Acceptor.
This class exists to aid a diagnostician/validator which will typically first check if a particular issue will be accepted at all (before checking for an occurrence of the issue; i.e. to perform check avoidance for expensive checks). A validator passes an instance of Issue, the semantic object (the “culprit”), a hash with arguments, and an optional exception. The semantic object is used to determine the location of the occurrence of the issue (file/line), and it sets keys in the given argument hash that may be used in the formatting of the issue message.
Instance Attribute Summary collapse
-
#label_provider ⇒ LabelProvider
readonly
A producer of labels for objects involved in the issue.
-
#severity_producer ⇒ SeverityProducer
readonly
A producer of severity for a given issue.
Instance Method Summary collapse
- #accept(issue, semantic, arguments = {}, except = nil) ⇒ Object
-
#initialize(acceptor, severity_producer, label_provider) ⇒ DiagnosticProducer
constructor
Initializes this producer.
- #will_accept?(issue) ⇒ Boolean
Constructor Details
#initialize(acceptor, severity_producer, label_provider) ⇒ DiagnosticProducer
Initializes this producer.
185 186 187 188 189 |
# File 'lib/puppet/pops/validation.rb', line 185 def initialize(acceptor, severity_producer, label_provider) @acceptor = acceptor @severity_producer = severity_producer @label_provider = label_provider end |
Instance Attribute Details
#label_provider ⇒ LabelProvider (readonly)
A producer of labels for objects involved in the issue
178 179 180 |
# File 'lib/puppet/pops/validation.rb', line 178 def label_provider @label_provider end |
#severity_producer ⇒ SeverityProducer (readonly)
A producer of severity for a given issue
173 174 175 |
# File 'lib/puppet/pops/validation.rb', line 173 def severity_producer @severity_producer end |
Instance Method Details
#accept(issue, semantic, arguments = {}, except = nil) ⇒ Object
191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 |
# File 'lib/puppet/pops/validation.rb', line 191 def accept(issue, semantic, arguments={}, except=nil) return unless will_accept? issue # Set label provider unless caller provided a special label provider arguments[:label] ||= @label_provider arguments[:semantic] ||= semantic # A detail message is always provided, but is blank by default. # TODO: this support is questionable, it requires knowledge that :detail is special arguments[:detail] ||= '' if semantic.is_a?(Puppet::Parser::Resource) source_pos = semantic file = semantic.file else source_pos = Puppet::Pops::Utils.find_closest_positioned(semantic) file = source_pos ? source_pos.locator.file : nil end severity = @severity_producer.severity(issue) @acceptor.accept(Diagnostic.new(severity, issue, file, source_pos, arguments, except)) end |
#will_accept?(issue) ⇒ Boolean
214 215 216 |
# File 'lib/puppet/pops/validation.rb', line 214 def will_accept? issue @severity_producer.should_report? issue end |