Exception: Foreman::Exception

Inherits:
StandardError
  • Object
show all
Defined in:
lib/foreman/exception.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message, *params) ⇒ Exception


4
5
6
7
# File 'lib/foreman/exception.rb', line 4

def initialize message, *params
  @message = message
  @params = params
end

Class Method Details

.calculate_error_code(classname, message) ⇒ Object

Error code is made up first 8 characters of base64 (RFC 4648) encoded MD5 sum of concatenated classname and message


11
12
13
14
15
# File 'lib/foreman/exception.rb', line 11

def self.calculate_error_code classname, message
  class_hash = Zlib::crc32(classname) % 100
  msg_hash = Zlib::crc32(message) % 10000
  sprintf "ERF%02d-%04d", class_hash, msg_hash
end

Instance Method Details

#codeObject


17
18
19
20
# File 'lib/foreman/exception.rb', line 17

def code
  @code ||= Exception.calculate_error_code self.class.name, @message
  @code
end

#messageObject Also known as: to_s


26
27
28
29
30
31
32
33
34
# File 'lib/foreman/exception.rb', line 26

def message
  # make sure it works without gettext too
  if Kernel.respond_to? :_
    translated_msg = _(@message) % @params
  else
    translated_msg = @message
  end
  "#{code}: #{translated_msg}"
end

#message_untranslatedObject


22
23
24
# File 'lib/foreman/exception.rb', line 22

def message_untranslated
  @message
end