Class: Puppet::Pops::Validation::DiagnosticProducer Private

Inherits:
Object
  • Object
show all
Defined in:
lib/puppet/pops/validation.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

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

Instance Method Summary collapse

Constructor Details

#initialize(acceptor, severity_producer, label_provider) ⇒ DiagnosticProducer

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.

Initializes this producer.

Parameters:

  • acceptor (Acceptor)

    a sink/collector of diagnostic results

  • severity_producer (SeverityProducer)

    the severity producer to use to determine severity of a given issue

  • label_provider (LabelProvider)

    a provider of model element type to human readable label



188
189
190
191
192
# File 'lib/puppet/pops/validation.rb', line 188

def initialize(acceptor, severity_producer, label_provider)
  @acceptor           = acceptor
  @severity_producer  = severity_producer
  @label_provider     = label_provider
end

Instance Attribute Details

#label_providerLabelProvider (readonly)

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.

A producer of labels for objects involved in the issue

Returns:



180
181
182
# File 'lib/puppet/pops/validation.rb', line 180

def label_provider
  @label_provider
end

#severity_producerSeverityProducer (readonly)

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.

A producer of severity for a given issue

Returns:



175
176
177
# File 'lib/puppet/pops/validation.rb', line 175

def severity_producer
  @severity_producer
end

Instance Method Details

#accept(issue, semantic, arguments = {}, except = nil) ⇒ 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.



194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
# File 'lib/puppet/pops/validation.rb', line 194

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] ||= ''

  # Accept an Error as semantic if it supports methods #file(), #line(), and #pos()
  if semantic.is_a?(StandardError)
    unless semantic.respond_to?(:file) && semantic.respond_to?(:line) && semantic.respond_to?(:pos)
      raise Puppet::DevError, _("Issue %{issue_code}: Cannot pass a %{class_name} as a semantic object when it does not support #pos(), #file() and #line()") %
                              { issue_code: issue.issue_code, class_name: semantic.class }
    end
  end

  source_pos = semantic
  file = semantic.file unless semantic.nil?

  severity = @severity_producer.severity(issue)
  @acceptor.accept(Diagnostic.new(severity, issue, file, source_pos, arguments, except))
end

#will_accept?(issue) ⇒ Boolean

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.

Returns:

  • (Boolean)


220
221
222
# File 'lib/puppet/pops/validation.rb', line 220

def will_accept? issue
  @severity_producer.should_report? issue
end