Class: Gandi::FaultCode

Inherits:
Object
  • Object
show all
Defined in:
lib/gandi/fault_code.rb,
lib/gandi/fault_code/data.rb,
lib/gandi/fault_code/server.rb,
lib/gandi/fault_code/unknown.rb

Direct Known Subclasses

Data, Server, Unknown

Defined Under Namespace

Classes: Data, Server, Unknown

Constant Summary collapse

QUALIF =
{Server::QUALIF => Server, Data::QUALIF => Data}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(object, cause, msg = nil) ⇒ FaultCode

Returns a new instance of FaultCode.



20
21
22
23
24
# File 'lib/gandi/fault_code.rb', line 20

def initialize(object, cause, msg = nil)
  @object = self.class::OBJECT[object] || :object_invalid
  @cause = self.class::CAUSE[cause] || :cause_invalid
  @msg = msg
end

Instance Attribute Details

#causeObject (readonly)

Returns the value of attribute cause.



18
19
20
# File 'lib/gandi/fault_code.rb', line 18

def cause
  @cause
end

#msgObject (readonly)

Returns the value of attribute msg.



18
19
20
# File 'lib/gandi/fault_code.rb', line 18

def msg
  @msg
end

#objectObject (readonly)

Returns the value of attribute object.



18
19
20
# File 'lib/gandi/fault_code.rb', line 18

def object
  @object
end

Class Method Details

.parse(code, msg = nil) ⇒ Object



9
10
11
12
13
14
15
16
# File 'lib/gandi/fault_code.rb', line 9

def self.parse(code, msg = nil)
  qualif = code / 100000
  object = code % 100000 / 100
  cause = code % 100

  klass = QUALIF.key?(qualif) ? QUALIF[qualif] : Unknown
  klass.new(object, cause, msg)
end

Instance Method Details

#exceptionObject



26
27
28
# File 'lib/gandi/fault_code.rb', line 26

def exception
  self.class::ERROR.new(msg, self)
end