Class: Inspec::Reporters::Base
- Inherits:
-
Object
- Object
- Inspec::Reporters::Base
- Defined in:
- lib/inspec/reporters/base.rb
Instance Attribute Summary collapse
-
#run_data ⇒ Object
readonly
Returns the value of attribute run_data.
Instance Method Summary collapse
-
#apply_report_resize_options ⇒ Object
Apply options such as message truncation and removal of backtraces.
-
#initialize(config) ⇒ Base
constructor
A new instance of Base.
- #output(str, newline = true) ⇒ Object
-
#render ⇒ Object
each reporter must implement #render.
- #rendered_output ⇒ Object
Constructor Details
#initialize(config) ⇒ Base
Returns a new instance of Base.
5 6 7 8 9 10 |
# File 'lib/inspec/reporters/base.rb', line 5 def initialize(config) @config = config @run_data = config[:run_data] unless @run_data.nil? @output = "" end |
Instance Attribute Details
#run_data ⇒ Object (readonly)
Returns the value of attribute run_data.
3 4 5 |
# File 'lib/inspec/reporters/base.rb', line 3 def run_data @run_data end |
Instance Method Details
#apply_report_resize_options ⇒ Object
Apply options such as message truncation and removal of backtraces
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/inspec/reporters/base.rb', line 13 def runtime_config = Inspec::Config.cached.respond_to?(:final_options) ? Inspec::Config.cached. : {} = runtime_config[:reporter_message_truncation] || "ALL" trunc = == "ALL" ? -1 : .to_i include_backtrace = runtime_config[:reporter_backtrace_inclusion].nil? ? true : runtime_config[:reporter_backtrace_inclusion] @run_data[:profiles]&.each do |p| p[:controls].each do |c| c[:results]&.map! do |r| r.delete(:backtrace) unless include_backtrace if r.key?(:message) && r[:message] != "" && trunc > -1 r[:message] = r[:message][0...trunc] + "[Truncated to #{trunc} characters]" end r end end end end |
#output(str, newline = true) ⇒ Object
33 34 35 36 |
# File 'lib/inspec/reporters/base.rb', line 33 def output(str, newline = true) @output << str @output << "\n" if newline end |
#render ⇒ Object
each reporter must implement #render
43 44 45 |
# File 'lib/inspec/reporters/base.rb', line 43 def render raise NotImplementedError, "#{self.class} must implement a `#render` method to format its output." end |
#rendered_output ⇒ Object
38 39 40 |
# File 'lib/inspec/reporters/base.rb', line 38 def rendered_output @output end |