Class: Chef::Formatters::Base

Inherits:
EventDispatch::Base show all
Includes:
ErrorMapper
Defined in:
lib/chef/formatters/base.rb

Overview

== Formatters::Base Base class that all formatters should inherit from.

Direct Known Subclasses

Doc, Minimal, NullFormatter

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ErrorMapper

cookbook_resolution_failed, cookbook_sync_failed, file_load_failed, node_load_failed, registration_failed, resource_failed, run_list_expand_failed

Methods inherited from EventDispatch::Base

#action_collection_registration, #attribute_changed, #attribute_load_complete, #attribute_load_start, #compliance_input_enabled, #compliance_input_loaded, #compliance_load_complete, #compliance_load_start, #compliance_profile_enabled, #compliance_profile_loaded, #compliance_waiver_enabled, #compliance_waiver_loaded, #converge_complete, #converge_failed, #converge_start, #cookbook_clean_complete, #cookbook_clean_start, #cookbook_compilation_complete, #cookbook_compilation_start, #cookbook_gem_failed, #cookbook_gem_finished, #cookbook_gem_installing, #cookbook_gem_start, #cookbook_gem_using, #cookbook_resolution_complete, #cookbook_resolution_start, #cookbook_sync_complete, #cookbook_sync_start, #definition_load_complete, #definition_load_start, #handler_executed, #handlers_completed, #handlers_start, #inputs_load_complete, #inputs_load_start, #key_migration_status, #library_load_complete, #library_load_start, #lwrp_load_complete, #lwrp_load_start, #msg, #node_load_completed, #node_load_start, #node_load_success, #ohai_completed, #ohai_plugin_file_load_failed, #ohai_plugin_file_loaded, #ohai_plugin_load_complete, #ohai_plugin_load_start, #policyfile_loaded, #profiles_load_complete, #profiles_load_start, #provider_requirement_failed, #recipe_load_complete, #recipe_load_start, #registration_completed, #registration_start, #removed_cookbook_file, #resource_action_start, #resource_after_state_loaded, #resource_bypassed, #resource_completed, #resource_current_state_load_bypassed, #resource_current_state_loaded, #resource_failed_retriable, #resource_skipped, #resource_up_to_date, #resource_update_applied, #resource_update_progress, #resource_updated, #run_completed, #run_failed, #run_list_expanded, #run_start, #run_started, #skipping_registration, #stream_closed, #stream_opened, #stream_output, #synchronized_cookbook, #updated_cookbook_file, #waivers_load_complete, #waivers_load_start, #whyrun_assumption

Constructor Details

#initialize(out, err) ⇒ Base

Returns a new instance of Base.



74
75
76
# File 'lib/chef/formatters/base.rb', line 74

def initialize(out, err)
  @output = IndentableOutputStream.new(out, err)
end

Instance Attribute Details

#errObject (readonly)

Returns the value of attribute err.



71
72
73
# File 'lib/chef/formatters/base.rb', line 71

def err
  @err
end

#outObject (readonly)

Returns the value of attribute out.



70
71
72
# File 'lib/chef/formatters/base.rb', line 70

def out
  @out
end

#outputObject (readonly)

Returns the value of attribute output.



72
73
74
# File 'lib/chef/formatters/base.rb', line 72

def output
  @output
end

Class Method Details

.cli_name(name) ⇒ Object



66
67
68
# File 'lib/chef/formatters/base.rb', line 66

def self.cli_name(name)
  Chef::Formatters.register(name, self)
end

Instance Method Details

#attribute_file_load_failed(path, exception) ⇒ Object

Delegates to #file_load_failed



190
191
192
# File 'lib/chef/formatters/base.rb', line 190

def attribute_file_load_failed(path, exception)
  file_load_failed(path, exception)
end

#attribute_file_loaded(path) ⇒ Object

Delegates to #file_loaded



185
186
187
# File 'lib/chef/formatters/base.rb', line 185

def attribute_file_loaded(path)
  file_loaded(path)
end

#cookbook_resolution_failed(expanded_run_list, exception) ⇒ Object



128
129
130
131
# File 'lib/chef/formatters/base.rb', line 128

def cookbook_resolution_failed(expanded_run_list, exception)
  description = ErrorMapper.cookbook_resolution_failed(expanded_run_list, exception)
  display_error(description)
end

#cookbook_sync_failed(cookbooks, exception) ⇒ Object



133
134
135
136
# File 'lib/chef/formatters/base.rb', line 133

def cookbook_sync_failed(cookbooks, exception)
  description = ErrorMapper.cookbook_sync_failed(cookbooks, exception)
  display_error(description)
end

#definition_file_load_failed(path, exception) ⇒ Object

Delegates to #file_load_failed



200
201
202
# File 'lib/chef/formatters/base.rb', line 200

def definition_file_load_failed(path, exception)
  file_load_failed(path, exception)
end

#definition_file_loaded(path) ⇒ Object

Delegates to #file_loaded



195
196
197
# File 'lib/chef/formatters/base.rb', line 195

def definition_file_loaded(path)
  file_loaded(path)
end

#deprecation(deprecation, _location = nil) ⇒ Object

Log a deprecation warning object.

Parameters:

  • deprecation (Chef::Deprecated::Base)

    Deprecation object to log. In previous versions, this could be a string. Don't do that anymore.

  • location (Object)

    Unused, present only for compatibility.



219
220
221
# File 'lib/chef/formatters/base.rb', line 219

def deprecation(deprecation, _location = nil)
  Chef::Log.deprecation(deprecation.to_s) unless deprecation.silenced?
end

#display_error(description) ⇒ Object

Input: a Formatters::ErrorDescription object. Outputs error to STDOUT.



107
108
109
110
# File 'lib/chef/formatters/base.rb', line 107

def display_error(description)
  puts("")
  description.display(output)
end

#file_load_failed(path, exception) ⇒ Object

Generic callback for any attribute/library/lwrp/recipe file throwing an exception when loaded. Default behavior is to use CompileErrorInspector to print contextual info about the failure.



154
155
156
157
# File 'lib/chef/formatters/base.rb', line 154

def file_load_failed(path, exception)
  description = ErrorMapper.file_load_failed(path, exception)
  display_error(description)
end

#file_loaded(path) ⇒ Object

Generic callback for any attribute/library/lwrp/recipe file in a cookbook getting loaded. The per-filetype callbacks for file load are overridden so that they call this instead. This means that a subclass of Formatters::Base can implement #file_loaded to do the same thing for every kind of file that Chef loads from a recipe instead of implementing all the per-filetype callbacks.



149
# File 'lib/chef/formatters/base.rb', line 149

def file_loaded(path); end

#indent_by(amount) ⇒ Object



94
95
96
97
98
99
100
101
102
103
# File 'lib/chef/formatters/base.rb', line 94

def indent_by(amount)
  @output.indent += amount
  if @output.indent < 0
    # This is left commented out for now.  We need to uncomment it and fix at least one bug in
    # the formatter, and then leave this line uncommented in the future.
    # Chef::Log.warn "Internal Formatter Error -- Attempt to indent by negative number of spaces"
    @output.indent = 0
  end
  @output.indent
end

#is_formatter?Boolean

Returns:

  • (Boolean)


227
228
229
# File 'lib/chef/formatters/base.rb', line 227

def is_formatter?
  true
end

#is_structured_deprecation?(deprecation) ⇒ Boolean

Returns:

  • (Boolean)


223
224
225
# File 'lib/chef/formatters/base.rb', line 223

def is_structured_deprecation?(deprecation)
  deprecation.is_a?(Chef::Deprecated::Base)
end

#library_file_load_failed(path, exception) ⇒ Object

Delegates to #file_load_failed



170
171
172
# File 'lib/chef/formatters/base.rb', line 170

def library_file_load_failed(path, exception)
  file_load_failed(path, exception)
end

#library_file_loaded(path) ⇒ Object

Delegates to #file_loaded



165
166
167
# File 'lib/chef/formatters/base.rb', line 165

def library_file_loaded(path)
  file_loaded(path)
end

#lwrp_file_load_failed(path, exception) ⇒ Object

Delegates to #file_load_failed



180
181
182
# File 'lib/chef/formatters/base.rb', line 180

def lwrp_file_load_failed(path, exception)
  file_load_failed(path, exception)
end

#lwrp_file_loaded(path) ⇒ Object

Delegates to #file_loaded



175
176
177
# File 'lib/chef/formatters/base.rb', line 175

def lwrp_file_loaded(path)
  file_loaded(path)
end

#node_load_failed(node_name, exception, config) ⇒ Object



118
119
120
121
# File 'lib/chef/formatters/base.rb', line 118

def node_load_failed(node_name, exception, config)
  description = ErrorMapper.node_load_failed(node_name, exception, config)
  display_error(description)
end


82
83
84
# File 'lib/chef/formatters/base.rb', line 82

def print(*args)
  @output.print(*args)
end

#puts(*args) ⇒ Object



78
79
80
# File 'lib/chef/formatters/base.rb', line 78

def puts(*args)
  @output.puts(*args)
end

#puts_line(*args) ⇒ Object



86
87
88
# File 'lib/chef/formatters/base.rb', line 86

def puts_line(*args)
  @output.puts_line(*args)
end

#recipe_file_load_failed(path, exception, recipe) ⇒ Object

Delegates to #file_load_failed



210
211
212
# File 'lib/chef/formatters/base.rb', line 210

def recipe_file_load_failed(path, exception, recipe)
  file_load_failed(path, exception)
end

#recipe_file_loaded(path, recipe) ⇒ Object

Delegates to #file_loaded



205
206
207
# File 'lib/chef/formatters/base.rb', line 205

def recipe_file_loaded(path, recipe)
  file_loaded(path)
end

#recipe_not_found(exception) ⇒ Object



159
160
161
162
# File 'lib/chef/formatters/base.rb', line 159

def recipe_not_found(exception)
  description = ErrorMapper.file_load_failed(nil, exception)
  display_error(description)
end

#registration_failed(node_name, exception, config) ⇒ Object



112
113
114
115
116
# File 'lib/chef/formatters/base.rb', line 112

def registration_failed(node_name, exception, config)
  # A Formatters::ErrorDescription object
  description = ErrorMapper.registration_failed(node_name, exception, config)
  display_error(description)
end

#resource_failed(resource, action, exception) ⇒ Object



138
139
140
141
# File 'lib/chef/formatters/base.rb', line 138

def resource_failed(resource, action, exception)
  description = ErrorMapper.resource_failed(resource, action, exception)
  display_error(description) unless resource.ignore_failure && resource.ignore_failure.to_s == "quiet"
end

#run_list_expand_failed(node, exception) ⇒ Object



123
124
125
126
# File 'lib/chef/formatters/base.rb', line 123

def run_list_expand_failed(node, exception)
  description = ErrorMapper.run_list_expand_failed(node, exception)
  display_error(description)
end

#start_line(*args) ⇒ Object



90
91
92
# File 'lib/chef/formatters/base.rb', line 90

def start_line(*args)
  @output.start_line(*args)
end