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 370 def initialize() 371 @diagnostics = [] 372 @error_count = 0 373 @warning_count = 0 374 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 413 def accept(diagnostic) 414 if diagnostic.is_a?(Acceptor) 415 diagnostic.diagnostics.each {|d| _accept(d)} 416 else 417 _accept(diagnostic) 418 end 419 end
Returns the diagnosed errors in the order they were reported.
# File lib/puppet/pops/validation.rb 392 def errors 393 @diagnostics.select {|d| d.severity == :error } 394 end
Returns true when errors have been diagnosed.
# File lib/puppet/pops/validation.rb 377 def errors? 378 @error_count > 0 379 end
# File lib/puppet/pops/validation.rb 402 def errors_and_warnings 403 @diagnostics.select {|d| d.severity != :ignore } 404 end
Returns true when errors and/or warnings have been diagnosed.
# File lib/puppet/pops/validation.rb 387 def errors_or_warnings? 388 errors? || warnings? 389 end
Returns the ignored diagnostics in the order they were reported (if reported at all)
# File lib/puppet/pops/validation.rb 407 def ignored 408 @diagnostics.select {|d| d.severity == :ignore } 409 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 425 def prune(&block) 426 removed = [] 427 @diagnostics.delete_if do |d| 428 should_remove = yield(d) 429 if should_remove 430 removed << d 431 end 432 should_remove 433 end 434 removed.each do |d| 435 case d.severity 436 when :error 437 @error_count -= 1 438 when :warning 439 @warning_count -= 1 440 # there is not ignore_count 441 end 442 end 443 removed.empty? ? nil : removed 444 end
Returns the diagnosed warnings in the order they were reported. (This includes :warning and :deprecation severity)
# File lib/puppet/pops/validation.rb 398 def warnings 399 @diagnostics.select {|d| d.severity == :warning || d.severity == :deprecation } 400 end
Returns true when warnings have been diagnosed.
# File lib/puppet/pops/validation.rb 382 def warnings? 383 @warning_count > 0 384 end
Private Instance Methods
# File lib/puppet/pops/validation.rb 448 def _accept(diagnostic) 449 @diagnostics << diagnostic 450 case diagnostic.severity 451 when :error 452 @error_count += 1 453 when :deprecation, :warning 454 @warning_count += 1 455 end 456 end