class Puppet::Pops::Validation::DiagnosticProducer
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.
Attributes
A producer of labels for objects involved in the issue @return [LabelProvider]
A producer of severity for a given issue @return [SeverityProducer]
Public Class Methods
Initializes this producer.
@param acceptor [Acceptor] a sink/collector of diagnostic results @param severity_producer [SeverityProducer] the severity producer to use to determine severity of a given issue @param label_provider [LabelProvider] a provider of model element type to human readable label
# File lib/puppet/pops/validation.rb 188 def initialize(acceptor, severity_producer, label_provider) 189 @acceptor = acceptor 190 @severity_producer = severity_producer 191 @label_provider = label_provider 192 end
Public Instance Methods
# File lib/puppet/pops/validation.rb 194 def accept(issue, semantic, arguments={}, except=nil) 195 return unless will_accept? issue 196 197 # Set label provider unless caller provided a special label provider 198 arguments[:label] ||= @label_provider 199 arguments[:semantic] ||= semantic 200 201 # A detail message is always provided, but is blank by default. 202 # TODO: this support is questionable, it requires knowledge that :detail is special 203 arguments[:detail] ||= '' 204 205 # Accept an Error as semantic if it supports methods #file(), #line(), and #pos() 206 if semantic.is_a?(StandardError) 207 unless semantic.respond_to?(:file) && semantic.respond_to?(:line) && semantic.respond_to?(:pos) 208 raise Puppet::DevError, _("Issue %{issue_code}: Cannot pass a %{class_name} as a semantic object when it does not support #pos(), #file() and #line()") % 209 { issue_code: issue.issue_code, class_name: semantic.class } 210 end 211 end 212 213 source_pos = semantic 214 file = semantic.file unless semantic.nil? 215 216 severity = @severity_producer.severity(issue) 217 @acceptor.accept(Diagnostic.new(severity, issue, file, source_pos, arguments, except)) 218 end
# File lib/puppet/pops/validation.rb 220 def will_accept? issue 221 @severity_producer.should_report? issue 222 end