Exception: Proxy::Ansible::Exception
- Inherits:
-
StandardError
- Object
- StandardError
- Proxy::Ansible::Exception
show all
- Defined in:
- lib/smart_proxy_ansible/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.
8
9
10
11
|
# File 'lib/smart_proxy_ansible/exception.rb', line 8
def initialize(message, *params)
@message = message
@params = params
end
|
Class Method Details
.calculate_error_code(classname, message) ⇒ Object
13
14
15
16
17
18
19
|
# File 'lib/smart_proxy_ansible/exception.rb', line 13
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
21
22
23
24
|
# File 'lib/smart_proxy_ansible/exception.rb', line 21
def code
@code ||= Exception.calculate_error_code(self.class.name, @message)
@code
end
|
#message ⇒ Object
26
27
28
29
30
|
# File 'lib/smart_proxy_ansible/exception.rb', line 26
def message
translated_msg = @message % @params
"#{code} [#{self.class.name}]: #{translated_msg}"
end
|
#to_s ⇒ Object
32
33
34
|
# File 'lib/smart_proxy_ansible/exception.rb', line 32
def to_s
message
end
|