Class: Puppet::Pops::Validation::Acceptor Private
- 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.
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.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#diagnostics ⇒ Object
readonly
private
All diagnostic in the order they were issued.
-
#error_count ⇒ Object
readonly
private
The number of :error severity issues.
-
#warning_count ⇒ Object
readonly
private
The number of :warning severity issues + number of :deprecation severity issues.
Instance Method Summary collapse
-
#accept(diagnostic) ⇒ Object
private
Add a diagnostic, or all diagnostics from another acceptor to the set of diagnostics.
-
#errors ⇒ Object
private
Returns the diagnosed errors in the order they were reported.
-
#errors? ⇒ Boolean
private
Returns true when errors have been diagnosed.
- #errors_and_warnings ⇒ Object private
-
#errors_or_warnings? ⇒ Boolean
private
Returns true when errors and/or warnings have been diagnosed.
-
#ignored ⇒ Object
private
Returns the ignored diagnostics in the order they were reported (if reported at all).
-
#initialize ⇒ Acceptor
constructor
private
Initializes this diagnostics acceptor.
-
#prune(&block) ⇒ Array<Diagnostic, nil] the removed set of diagnostics or nil if nothing was removed
private
Prunes the contain diagnostics by removing those for which the given block returns true.
-
#warnings ⇒ Object
private
Returns the diagnosed warnings in the order they were reported.
-
#warnings? ⇒ Boolean
private
Returns true when warnings have been diagnosed.
Constructor Details
#initialize ⇒ Acceptor
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 diagnostics acceptor. By default, the acceptor is configured with a default severity producer. TODO add semantic_label_provider
368 369 370 371 372 |
# File 'lib/puppet/pops/validation.rb', line 368 def initialize() @diagnostics = [] @error_count = 0 @warning_count = 0 end |
Instance Attribute Details
#diagnostics ⇒ Object (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.
All diagnostic in the order they were issued
355 356 357 |
# File 'lib/puppet/pops/validation.rb', line 355 def diagnostics @diagnostics end |
#error_count ⇒ Object (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.
The number of :error severity issues
361 362 363 |
# File 'lib/puppet/pops/validation.rb', line 361 def error_count @error_count end |
#warning_count ⇒ Object (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.
The number of :warning severity issues + number of :deprecation severity issues
358 359 360 |
# File 'lib/puppet/pops/validation.rb', line 358 def warning_count @warning_count end |
Instance Method Details
#accept(diagnostic) ⇒ 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.
Add a diagnostic, or all diagnostics from another acceptor to the set of diagnostics
411 412 413 414 415 416 417 |
# File 'lib/puppet/pops/validation.rb', line 411 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 ⇒ 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.
Returns the diagnosed errors in the order they were reported.
390 391 392 |
# File 'lib/puppet/pops/validation.rb', line 390 def errors @diagnostics.select {|d| d.severity == :error } end |
#errors? ⇒ 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 true when errors have been diagnosed.
375 376 377 |
# File 'lib/puppet/pops/validation.rb', line 375 def errors? @error_count > 0 end |
#errors_and_warnings ⇒ 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.
400 401 402 |
# File 'lib/puppet/pops/validation.rb', line 400 def errors_and_warnings @diagnostics.select {|d| d.severity != :ignore } end |
#errors_or_warnings? ⇒ 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 true when errors and/or warnings have been diagnosed.
385 386 387 |
# File 'lib/puppet/pops/validation.rb', line 385 def errors_or_warnings? errors? || warnings? end |
#ignored ⇒ 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.
Returns the ignored diagnostics in the order they were reported (if reported at all)
405 406 407 |
# File 'lib/puppet/pops/validation.rb', line 405 def ignored @diagnostics.select {|d| d.severity == :ignore } end |
#prune(&block) ⇒ Array<Diagnostic, nil] the removed set of diagnostics or nil if nothing was removed
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.
Prunes the contain diagnostics by removing those for which the given block returns true. The internal statistics is updated as a consequence of removing.
423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 |
# File 'lib/puppet/pops/validation.rb', line 423 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 ⇒ 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.
Returns the diagnosed warnings in the order they were reported. (This includes :warning and :deprecation severity)
396 397 398 |
# File 'lib/puppet/pops/validation.rb', line 396 def warnings @diagnostics.select {|d| d.severity == :warning || d.severity == :deprecation } end |
#warnings? ⇒ 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 true when warnings have been diagnosed.
380 381 382 |
# File 'lib/puppet/pops/validation.rb', line 380 def warnings? @warning_count > 0 end |