Module: MotherBrain::Errors

Defined in:
lib/mb/errors.rb

Class Method Summary collapse

Class Method Details

.error_codesHash

Returns:

  • (Hash)


5
6
7
# File 'lib/mb/errors.rb', line 5

def error_codes
  @error_codes ||= Hash.new
end

.register(klass) ⇒ Object

Parameters:

Raises:

  • (RuntimeError)


12
13
14
15
16
17
18
19
20
# File 'lib/mb/errors.rb', line 12

def register(klass)
  if error_codes.has_key?(klass.error_code)
    msg = "Unable to register exception #{klass}. The error_code #{klass.error_code} is already"
    msg << " in use by #{error_codes[klass.error_code]}."
    raise RuntimeError, msg
  end

  error_codes[klass.error_code] = klass
end

.unregister(klass) ⇒ Object

Parameters:



23
24
25
# File 'lib/mb/errors.rb', line 23

def unregister(klass)
  error_codes.delete(klass.error_code)
end