Class: InspecTools::Summary
Overview
rubocop:disable Metrics/ClassLength
Instance Attribute Summary collapse
-
#json ⇒ Object
readonly
Returns the value of attribute json.
-
#json_counts ⇒ Object
readonly
Returns the value of attribute json_counts.
-
#json_full ⇒ Object
readonly
Returns the value of attribute json_full.
-
#summary ⇒ Object
readonly
Returns the value of attribute summary.
-
#threshold ⇒ Object
readonly
Returns the value of attribute threshold.
-
#threshold_file ⇒ Object
readonly
Returns the value of attribute threshold_file.
-
#threshold_inline ⇒ Object
readonly
Returns the value of attribute threshold_inline.
Instance Method Summary collapse
-
#initialize(**options) ⇒ Summary
constructor
A new instance of Summary.
- #output_summary ⇒ Object
- #results_meet_threshold? ⇒ Boolean
Constructor Details
#initialize(**options) ⇒ Summary
Returns a new instance of Summary.
27 28 29 30 31 32 33 34 35 |
# File 'lib/inspec_tools/summary.rb', line 27 def initialize(**) = [:options] @json = JSON.parse(File.read([:inspec_json])) @json_full = false || [:json_full] @json_counts = false || [:json_counts] @threshold = parse_threshold([:threshold_inline], [:threshold_file]) @threshold_provided = [:threshold_inline] || [:threshold_file] @summary = compute_summary end |
Instance Attribute Details
#json ⇒ Object (readonly)
Returns the value of attribute json.
19 20 21 |
# File 'lib/inspec_tools/summary.rb', line 19 def json @json end |
#json_counts ⇒ Object (readonly)
Returns the value of attribute json_counts.
21 22 23 |
# File 'lib/inspec_tools/summary.rb', line 21 def json_counts @json_counts end |
#json_full ⇒ Object (readonly)
Returns the value of attribute json_full.
20 21 22 |
# File 'lib/inspec_tools/summary.rb', line 20 def json_full @json_full end |
#summary ⇒ Object (readonly)
Returns the value of attribute summary.
24 25 26 |
# File 'lib/inspec_tools/summary.rb', line 24 def summary @summary end |
#threshold ⇒ Object (readonly)
Returns the value of attribute threshold.
25 26 27 |
# File 'lib/inspec_tools/summary.rb', line 25 def threshold @threshold end |
#threshold_file ⇒ Object (readonly)
Returns the value of attribute threshold_file.
22 23 24 |
# File 'lib/inspec_tools/summary.rb', line 22 def threshold_file @threshold_file end |
#threshold_inline ⇒ Object (readonly)
Returns the value of attribute threshold_inline.
23 24 25 |
# File 'lib/inspec_tools/summary.rb', line 23 def threshold_inline @threshold_inline end |
Instance Method Details
#output_summary ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/inspec_tools/summary.rb', line 37 def output_summary unless @json_full || @json_counts puts "\nThreshold compliance: #{@threshold['compliance.min']}%" puts "\nOverall compliance: #{@summary[:compliance]}%\n\n" @summary[:status].keys.each do |category| puts category @summary[:status][category].keys.each do |impact| puts "\t#{impact} : #{@summary[:status][category][impact]}" end end end puts @summary.to_json if @json_full puts @summary[:status].to_json if @json_counts end |
#results_meet_threshold? ⇒ Boolean
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/inspec_tools/summary.rb', line 53 def results_meet_threshold? raise 'Please provide threshold as a yaml file or inline yaml' unless @threshold_provided compliance = true failure = [] failure << check_max_compliance(@threshold['compliance.max'], @summary[:compliance], '', 'compliance') failure << check_min_compliance(@threshold['compliance.min'], @summary[:compliance], '', 'compliance') BUCKETS.each do |bucket| TALLYS.each do |tally| failure << check_min_compliance(@threshold["#{bucket}.#{tally}.min"], @summary[:status][bucket][tally], bucket, tally) failure << check_max_compliance(@threshold["#{bucket}.#{tally}.max"], @summary[:status][bucket][tally], bucket, tally) end end failure.reject!(&:nil?) compliance = false if failure.length.positive? output(compliance, failure) compliance end |