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
All diagnostic in the order they were issued
The number of :error severity issues
The number of :warning severity issues + number of :deprecation severity issues
Public Class Methods
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 371 def initialize() 372 @diagnostics = [] 373 @error_count = 0 374 @warning_count = 0 375 end
Public Instance Methods
Add a diagnostic, or all diagnostics from another acceptor to the set of diagnostics @param diagnostic [Diagnostic, Acceptor] diagnostic(s) that should be accepted
# File lib/puppet/pops/validation.rb 414 def accept(diagnostic) 415 if diagnostic.is_a?(Acceptor) 416 diagnostic.diagnostics.each {|d| _accept(d)} 417 else 418 _accept(diagnostic) 419 end 420 end
Returns the diagnosed errors in the order they were reported.
# File lib/puppet/pops/validation.rb 393 def errors 394 @diagnostics.select {|d| d.severity == :error } 395 end
Returns true when errors have been diagnosed.
# File lib/puppet/pops/validation.rb 378 def errors? 379 @error_count > 0 380 end
# File lib/puppet/pops/validation.rb 403 def errors_and_warnings 404 @diagnostics.select {|d| d.severity != :ignore } 405 end
Returns true when errors and/or warnings have been diagnosed.
# File lib/puppet/pops/validation.rb 388 def errors_or_warnings? 389 errors? || warnings? 390 end
Returns the ignored diagnostics in the order they were reported (if reported at all)
# File lib/puppet/pops/validation.rb 408 def ignored 409 @diagnostics.select {|d| d.severity == :ignore } 410 end
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<Diagnostic, nil] the removed set of diagnostics or nil if nothing was removed
# File lib/puppet/pops/validation.rb 426 def prune(&block) 427 removed = [] 428 @diagnostics.delete_if do |d| 429 should_remove = yield(d) 430 if should_remove 431 removed << d 432 end 433 should_remove 434 end 435 removed.each do |d| 436 case d.severity 437 when :error 438 @error_count -= 1 439 when :warning 440 @warning_count -= 1 441 # there is not ignore_count 442 end 443 end 444 removed.empty? ? nil : removed 445 end
Returns the diagnosed warnings in the order they were reported. (This includes :warning and :deprecation severity)
# File lib/puppet/pops/validation.rb 399 def warnings 400 @diagnostics.select {|d| d.severity == :warning || d.severity == :deprecation } 401 end
Returns true when warnings have been diagnosed.
# File lib/puppet/pops/validation.rb 383 def warnings? 384 @warning_count > 0 385 end
Private Instance Methods
# File lib/puppet/pops/validation.rb 449 def _accept(diagnostic) 450 @diagnostics << diagnostic 451 case diagnostic.severity 452 when :error 453 @error_count += 1 454 when :deprecation, :warning 455 @warning_count += 1 456 end 457 end