Method: ChefApply::Text::ErrorTranslation#initialize

Defined in:
lib/chef_apply/text/error_translation.rb

#initialize(id, params: []) ⇒ ErrorTranslation

Returns a new instance of ErrorTranslation.



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/chef_apply/text/error_translation.rb', line 24

def initialize(id, params: [])
  # To get access to the metadata we'll go directly through the parsed yaml.
  # Accessing via R18n is unnecessarily complicated
  yml = Text._error_table

  # We'll still use our Text mechanism for the text itself so that
  # parameters, pluralization, etc will still work.
  # This will raise if the key doesn't exist.
  @message = Text.errors.send(id).text(*params)
  options = yml[:display_defaults]

  # Override any defaults if display metadata is given
  display_opts = yml[id.to_sym][:display]
  options = options.merge(display_opts) unless display_opts.nil?

  ATTRIBUTES.each do |attribute|
    instance_variable_set("@#{attribute}", options.delete(attribute))
  end

  if options.length > 0
    # Anything not in ATTRIBUTES is not supported. This will also catch
    # typos in attr names
    raise InvalidDisplayAttributes.new(id, options)
  end
end