Exception: ForemanAnsibleCore::Exception
- Inherits:
-
StandardError
- Object
- StandardError
- ForemanAnsibleCore::Exception
show all
- Defined in:
- lib/foreman_ansible_core/exception.rb
Overview
Taken from Foreman core, this class creates an error code for any exception
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(message, *params) ⇒ Exception
Returns a new instance of Exception.
6
7
8
9
|
# File 'lib/foreman_ansible_core/exception.rb', line 6
def initialize(message, *params)
@message = message
@params = params
end
|
Class Method Details
.calculate_error_code(classname, message) ⇒ Object
11
12
13
14
15
16
17
|
# File 'lib/foreman_ansible_core/exception.rb', line 11
def self.calculate_error_code(classname, message)
return 'ERF00-0000' if classname.nil? || message.nil?
basename = classname.split(':').last
class_hash = Zlib.crc32(basename) % 100
msg_hash = Zlib.crc32(message) % 10_000
format 'ERF%02d-%04d', class_hash, msg_hash
end
|
Instance Method Details
#code ⇒ Object
19
20
21
22
|
# File 'lib/foreman_ansible_core/exception.rb', line 19
def code
@code ||= Exception.calculate_error_code(self.class.name, @message)
@code
end
|
#message ⇒ Object
24
25
26
27
28
|
# File 'lib/foreman_ansible_core/exception.rb', line 24
def message
translated_msg = @message % @params
"#{code} [#{self.class.name}]: #{translated_msg}"
end
|
#to_s ⇒ Object
30
31
32
|
# File 'lib/foreman_ansible_core/exception.rb', line 30
def to_s
message
end
|