Class: Chef::Formatters::ErrorDescription

Inherits:
Object
  • Object
show all
Defined in:
lib/chef/formatters/error_description.rb

Overview

== Formatters::ErrorDescription Class for displaying errors on STDOUT.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(title) ⇒ ErrorDescription


30
31
32
33
# File 'lib/chef/formatters/error_description.rb', line 30

def initialize(title)
  @title = title
  @sections = []
end

Instance Attribute Details

#sectionsObject (readonly)

Returns the value of attribute sections


28
29
30
# File 'lib/chef/formatters/error_description.rb', line 28

def sections
  @sections
end

Instance Method Details

#display(out) ⇒ Object


39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/chef/formatters/error_description.rb', line 39

def display(out)
  out.puts "=" * 80
  out.puts @title, :red
  out.puts "=" * 80
  out.puts "\n"

  sections.each do |section|
    section.each do |heading, text|
      display_section(heading, text, out)
    end
  end
  display_section("System Info:", error_context_info, out)
end

#for_jsonObject


53
54
55
56
57
58
# File 'lib/chef/formatters/error_description.rb', line 53

def for_json
  {
    "title" => @title,
    "sections" => @sections,
  }
end

#section(heading, text) ⇒ Object


35
36
37
# File 'lib/chef/formatters/error_description.rb', line 35

def section(heading, text)
  @sections << { heading => (text || "") }
end