Class: InspecTools::Summary
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.
20 21 22 23 24 25 26 27 28 |
# File 'lib/inspec_tools/summary.rb', line 20 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.
18 19 20 |
# File 'lib/inspec_tools/summary.rb', line 18 def json @json end |
#json_counts ⇒ Object (readonly)
Returns the value of attribute json_counts.
18 19 20 |
# File 'lib/inspec_tools/summary.rb', line 18 def json_counts @json_counts end |
#json_full ⇒ Object (readonly)
Returns the value of attribute json_full.
18 19 20 |
# File 'lib/inspec_tools/summary.rb', line 18 def json_full @json_full end |
#summary ⇒ Object (readonly)
Returns the value of attribute summary.
18 19 20 |
# File 'lib/inspec_tools/summary.rb', line 18 def summary @summary end |
#threshold ⇒ Object (readonly)
Returns the value of attribute threshold.
18 19 20 |
# File 'lib/inspec_tools/summary.rb', line 18 def threshold @threshold end |
#threshold_file ⇒ Object (readonly)
Returns the value of attribute threshold_file.
18 19 20 |
# File 'lib/inspec_tools/summary.rb', line 18 def threshold_file @threshold_file end |
#threshold_inline ⇒ Object (readonly)
Returns the value of attribute threshold_inline.
18 19 20 |
# File 'lib/inspec_tools/summary.rb', line 18 def threshold_inline @threshold_inline end |
Instance Method Details
#output_summary ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/inspec_tools/summary.rb', line 30 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
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/inspec_tools/summary.rb', line 46 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 |