Class: ChefCore::Text::ErrorTranslation
- Inherits:
-
Object
- Object
- ChefCore::Text::ErrorTranslation
- Defined in:
- lib/chef_core/text/error_translation.rb
Overview
Represents an error loaded from translation, with display attributes set.
Defined Under Namespace
Classes: InvalidDisplayAttributes
Constant Summary collapse
- ATTRIBUTES =
[:decorations, :header, :footer, :stack, :log].freeze
Instance Method Summary collapse
-
#initialize(id, params: []) ⇒ ErrorTranslation
constructor
A new instance of ErrorTranslation.
- #inspect ⇒ Object
Constructor Details
#initialize(id, params: []) ⇒ ErrorTranslation
Returns a new instance of ErrorTranslation.
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/chef_core/text/error_translation.rb', line 26 def initialize(id, params: []) error_translation = error_translation_for_id(id) = YAML.load(Text.errors.display_defaults, "display_defaults", symbolize_names: true) # Display metadata is a string containing a YAML hash that is optionally under # the error's 'options' attribute # Note that we couldn't use :display, as that conflicts with a method on Object. display_opts = if error_translation.methods.include?(:options) YAML.load(error_translation., @id, symbolize_names: true) else {} end = .merge(display_opts) unless display_opts.nil? = error_translation.text(*params) ATTRIBUTES.each do |attribute| instance_variable_set("@#{attribute}", .delete(attribute)) end if .length > 0 # Anything not in ATTRIBUTES is not supported. This will also catch # typos in attr names raise InvalidDisplayAttributes.new(id, ) end end |
Instance Method Details
#inspect ⇒ Object
56 57 58 59 60 61 62 63 |
# File 'lib/chef_core/text/error_translation.rb', line 56 def inspect inspection = "#{self}: " ATTRIBUTES.each do |attribute| inspection << "#{attribute}: #{send(attribute.to_s)}; " end inspection << "message: #{message.gsub("\n", "\\n")}" inspection end |