Class: Puppet::Util::Assertion::Reporter
- Inherits:
-
Object
- Object
- Puppet::Util::Assertion::Reporter
- Includes:
- Printer::Styler
- Defined in:
- lib/puppet/util/assertion/reporter.rb
Instance Attribute Summary collapse
-
#evaluated ⇒ Object
readonly
Returns the value of attribute evaluated.
-
#failed ⇒ Object
readonly
Returns the value of attribute failed.
Instance Method Summary collapse
-
#<<(assertion) ⇒ Object
Given an assertion resource, evaluate it for success and send it to .report on failure.
- #count ⇒ Object
- #fail ⇒ Object
-
#initialize ⇒ Reporter
constructor
A new instance of Reporter.
- #print_error(err) ⇒ Object
-
#print_footer ⇒ Object
Print the summary of evaluated assertions.
-
#report(assertion) ⇒ Object
Pretty print the results of an assertion to the console.
Constructor Details
#initialize ⇒ Reporter
Returns a new instance of Reporter.
10 11 12 13 |
# File 'lib/puppet/util/assertion/reporter.rb', line 10 def initialize @evaluated = 0 @failed = 0 end |
Instance Attribute Details
#evaluated ⇒ Object (readonly)
Returns the value of attribute evaluated.
8 9 10 |
# File 'lib/puppet/util/assertion/reporter.rb', line 8 def evaluated @evaluated end |
#failed ⇒ Object (readonly)
Returns the value of attribute failed.
8 9 10 |
# File 'lib/puppet/util/assertion/reporter.rb', line 8 def failed @failed end |
Instance Method Details
#<<(assertion) ⇒ Object
Given an assertion resource, evaluate it for success and send it to .report on failure. Increment the counter for each resource, and the failed counter for failed resources.
18 19 20 21 22 23 24 |
# File 'lib/puppet/util/assertion/reporter.rb', line 18 def <<(assertion) count if assertion.provider.failed? fail report(assertion) end end |
#count ⇒ Object
72 73 74 |
# File 'lib/puppet/util/assertion/reporter.rb', line 72 def count @evaluated += 1 end |
#fail ⇒ Object
76 77 78 |
# File 'lib/puppet/util/assertion/reporter.rb', line 76 def fail @failed += 1 end |
#print_error(err) ⇒ Object
40 41 42 43 44 45 |
# File 'lib/puppet/util/assertion/reporter.rb', line 40 def print_error(err) fail #Mark an assertion so the application exits 1 style do red err. end end |
#print_footer ⇒ Object
Print the summary of evaluated assertions
27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/puppet/util/assertion/reporter.rb', line 27 def # Shim the reporter into the local scope reporter = self style do if reporter.evaluated == 1 yellow "Evaluated 1 assertion\n" else yellow "Evaluated #{reporter.evaluated} assertions\n" end end end |
#report(assertion) ⇒ Object
Pretty print the results of an assertion to the console
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/puppet/util/assertion/reporter.rb', line 48 def report(assertion) # Shim the value of failed into the # local scope in order to access it # from the style proc. failed = @failed style do red "#{failed}) Assertion #{assertion[:name]} failed on #{assertion[:subject].to_s}" newline yellow " On line #{assertion[:subject].line} of #{assertion.provider.relative_path}" newline blue " Wanted: " white assertion.provider.wanted.to_s newline blue " Got: " white assertion.provider.got.to_s newline newline end end |