class Puppet::Pops::Validation::Acceptor

An acceptor of diagnostics. An acceptor of diagnostics is given each issue as they are found by a diagnostician/validator. An acceptor can collect all found issues, or decide to collect a few and then report, or give up as the first issue if found. This default implementation collects all diagnostics in the order they are produced, and can then answer questions about what was diagnosed.

Attributes

diagnostics[R]

All diagnostic in the order they were issued

error_count[R]

The number of :error severity issues

warning_count[R]

The number of :warning severity issues + number of :deprecation severity issues

Public Instance Methods

accept(diagnostic) click to toggle source

Add a diagnostic, or all diagnostics from another acceptor to the set of diagnostics @param diagnostic [Puppet::Pops::Validation::Diagnostic, Puppet::Pops::Validation::Acceptor] diagnostic(s) that should be accepted

# File lib/puppet/pops/validation.rb, line 403
def accept(diagnostic)
  if diagnostic.is_a?(Acceptor)
    diagnostic.diagnostics.each {|d| self.send(d.severity, d)}
  else
    self.send(diagnostic.severity, diagnostic)
  end
end
errors() click to toggle source

Returns the diagnosed errors in the order thwy were reported.

# File lib/puppet/pops/validation.rb, line 382
def errors
  @diagnostics.select {|d| d.severity == :error }
end
errors?() click to toggle source

Returns true when errors have been diagnosed.

# File lib/puppet/pops/validation.rb, line 367
def errors?
  @error_count > 0
end
errors_and_warnings() click to toggle source
# File lib/puppet/pops/validation.rb, line 392
def errors_and_warnings
  @diagnostics.select {|d| d.severity != :ignore }
end
errors_or_warnings?() click to toggle source

Returns true when errors and/or warnings have been diagnosed.

# File lib/puppet/pops/validation.rb, line 377
def errors_or_warnings?
  errors? || warnings?
end
ignored() click to toggle source

Returns the ignored diagnostics in the order thwy were reported (if reported at all)

# File lib/puppet/pops/validation.rb, line 397
def ignored
  @diagnostics.select {|d| d.severity == :ignore }
end
prune() { |d| ... } click to toggle source

Prunes the contain diagnostics by removing those for which the given block returns true. The internal statistics is updated as a consequence of removing. @return [Array<Puppet::Pops::Validation::Diagnostic, nil] the removed set of diagnostics or nil if nothing was removed

# File lib/puppet/pops/validation.rb, line 415
def prune(&block)
  removed = []
  @diagnostics.delete_if do |d|
    if should_remove = yield(d)
      removed << d
    end
    should_remove
  end
  removed.each do |d|
    case d.severity
    when :error
      @error_count -= 1
    when :warning
      @warning_count -= 1
    # there is not ignore_count
    end
  end
  removed.empty? ? nil : removed
end
warnings() click to toggle source

Returns the diagnosed warnings in the order thwy were reported. (This includes :warning and :deprecation severity)

# File lib/puppet/pops/validation.rb, line 388
def warnings
  @diagnostics.select {|d| d.severity == :warning || d.severity == :deprecation }
end
warnings?() click to toggle source

Returns true when warnings have been diagnosed.

# File lib/puppet/pops/validation.rb, line 372
def warnings?
  @warning_count > 0
end

Public Class Methods

new() click to toggle source

Initializes this diagnostics acceptor. By default, the acceptor is configured with a default severity producer. @param severity_producer [SeverityProducer] the severity producer to use to determine severity of an issue

TODO add semantic_label_provider

# File lib/puppet/pops/validation.rb, line 360
def initialize()
  @diagnostics = []
  @error_count = 0
  @warning_count = 0
end