Class: Puppet::Pops::Validation::Acceptor
- Defined in:
- lib/puppet/pops/validation.rb
Overview
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
All diagnostic in the order they were issued.
-
#error_count ⇒ Object
readonly
The number of :error severity issues.
-
#warning_count ⇒ Object
readonly
The number of :warning severity issues + number of :deprecation severity issues.
Instance Method Summary collapse
-
#accept(diagnostic) ⇒ Object
Add a diagnostic, or all diagnostics from another acceptor to the set of diagnostics.
-
#errors ⇒ Object
Returns the diagnosed errors in the order thwy were reported.
-
#errors? ⇒ Boolean
Returns true when errors have been diagnosed.
- #errors_and_warnings ⇒ Object
-
#errors_or_warnings? ⇒ Boolean
Returns true when errors and/or warnings have been diagnosed.
-
#ignored ⇒ Object
Returns the ignored diagnostics in the order thwy were reported (if reported at all).
-
#initialize ⇒ Acceptor
constructor
Initializes this diagnostics acceptor.
-
#prune(&block) ⇒ Array<Puppet::Pops::Validation::Diagnostic, nil] the removed set of diagnostics or nil if nothing was removed
Prunes the contain diagnostics by removing those for which the given block returns true.
-
#warnings ⇒ Object
Returns the diagnosed warnings in the order thwy were reported.
-
#warnings? ⇒ Boolean
Returns true when warnings have been diagnosed.
Constructor Details
#initialize ⇒ Acceptor
Initializes this diagnostics acceptor. By default, the acceptor is configured with a default severity producer. TODO add semantic_label_provider
337 338 339 340 341 |
# File 'lib/puppet/pops/validation.rb', line 337 def initialize() @diagnostics = [] @error_count = 0 @warning_count = 0 end |
Instance Attribute Details
#diagnostics ⇒ Object (readonly)
All diagnostic in the order they were issued
324 325 326 |
# File 'lib/puppet/pops/validation.rb', line 324 def diagnostics @diagnostics end |
#error_count ⇒ Object (readonly)
The number of :error severity issues
330 331 332 |
# File 'lib/puppet/pops/validation.rb', line 330 def error_count @error_count end |
#warning_count ⇒ Object (readonly)
The number of :warning severity issues + number of :deprecation severity issues
327 328 329 |
# File 'lib/puppet/pops/validation.rb', line 327 def warning_count @warning_count end |
Instance Method Details
#accept(diagnostic) ⇒ Object
Add a diagnostic, or all diagnostics from another acceptor to the set of diagnostics
380 381 382 383 384 385 386 |
# File 'lib/puppet/pops/validation.rb', line 380 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
Returns the diagnosed errors in the order thwy were reported.
359 360 361 |
# File 'lib/puppet/pops/validation.rb', line 359 def errors @diagnostics.select {|d| d.severity == :error } end |
#errors? ⇒ Boolean
Returns true when errors have been diagnosed.
344 345 346 |
# File 'lib/puppet/pops/validation.rb', line 344 def errors? @error_count > 0 end |
#errors_and_warnings ⇒ Object
369 370 371 |
# File 'lib/puppet/pops/validation.rb', line 369 def errors_and_warnings @diagnostics.select {|d| d.severity != :ignore } end |
#errors_or_warnings? ⇒ Boolean
Returns true when errors and/or warnings have been diagnosed.
354 355 356 |
# File 'lib/puppet/pops/validation.rb', line 354 def errors_or_warnings? errors? || warnings? end |
#ignored ⇒ Object
Returns the ignored diagnostics in the order thwy were reported (if reported at all)
374 375 376 |
# File 'lib/puppet/pops/validation.rb', line 374 def ignored @diagnostics.select {|d| d.severity == :ignore } end |
#prune(&block) ⇒ Array<Puppet::Pops::Validation::Diagnostic, nil] the removed set of diagnostics or nil if nothing was removed
Prunes the contain diagnostics by removing those for which the given block returns true. The internal statistics is updated as a consequence of removing.
392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 |
# File 'lib/puppet/pops/validation.rb', line 392 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
Returns the diagnosed warnings in the order thwy were reported. (This includes :warning and :deprecation severity)
365 366 367 |
# File 'lib/puppet/pops/validation.rb', line 365 def warnings @diagnostics.select {|d| d.severity == :warning || d.severity == :deprecation } end |
#warnings? ⇒ Boolean
Returns true when warnings have been diagnosed.
349 350 351 |
# File 'lib/puppet/pops/validation.rb', line 349 def warnings? @warning_count > 0 end |