Class: Puppet::Pops::Validation::Acceptor

Inherits:
Object
  • Object
show all
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.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeAcceptor

Initializes this diagnostics acceptor. By default, the acceptor is configured with a default severity producer. TODO add semantic_label_provider

Parameters:

  • severity_producer (SeverityProducer)

    the severity producer to use to determine severity of an issue



365
366
367
368
369
# File 'lib/puppet/pops/validation.rb', line 365

def initialize()
  @diagnostics = []
  @error_count = 0
  @warning_count = 0
end

Instance Attribute Details

#diagnosticsObject (readonly)

All diagnostic in the order they were issued



352
353
354
# File 'lib/puppet/pops/validation.rb', line 352

def diagnostics
  @diagnostics
end

#error_countObject (readonly)

The number of :error severity issues



358
359
360
# File 'lib/puppet/pops/validation.rb', line 358

def error_count
  @error_count
end

#warning_countObject (readonly)

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



355
356
357
# File 'lib/puppet/pops/validation.rb', line 355

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

Parameters:



408
409
410
411
412
413
414
# File 'lib/puppet/pops/validation.rb', line 408

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

#errorsObject

Returns the diagnosed errors in the order thwy were reported.



387
388
389
# File 'lib/puppet/pops/validation.rb', line 387

def errors
  @diagnostics.select {|d| d.severity == :error }
end

#errors?Boolean

Returns true when errors have been diagnosed.

Returns:

  • (Boolean)


372
373
374
# File 'lib/puppet/pops/validation.rb', line 372

def errors?
  @error_count > 0
end

#errors_and_warningsObject



397
398
399
# File 'lib/puppet/pops/validation.rb', line 397

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.

Returns:

  • (Boolean)


382
383
384
# File 'lib/puppet/pops/validation.rb', line 382

def errors_or_warnings?
  errors? || warnings?
end

#ignoredObject

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



402
403
404
# File 'lib/puppet/pops/validation.rb', line 402

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.

Returns:



420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
# File 'lib/puppet/pops/validation.rb', line 420

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

#warningsObject

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



393
394
395
# File 'lib/puppet/pops/validation.rb', line 393

def warnings
  @diagnostics.select {|d| d.severity == :warning || d.severity == :deprecation }
end

#warnings?Boolean

Returns true when warnings have been diagnosed.

Returns:

  • (Boolean)


377
378
379
# File 'lib/puppet/pops/validation.rb', line 377

def warnings?
  @warning_count > 0
end