class ChefApply::Text::ErrorTranslation
Constants
- ATTRIBUTES
Attributes
message[R]
Public Class Methods
new(id, params: [])
click to toggle source
# 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
Public Instance Methods
inspect()
click to toggle source
# File lib/chef_apply/text/error_translation.rb, line 50 def inspect inspection = "#{self}: " ATTRIBUTES.each do |attribute| inspection << "#{attribute}: #{send(attribute.to_s)}; " end inspection << "message: #{message.gsub("\n", "\\n")}" inspection end