class Merb::ControllerExceptions::Base

Public Class Methods

inherited(subclass) click to toggle source

Registers any subclasses with status codes for easy lookup by set_status in Merb::Controller.

Inheritance ensures this method gets inherited by any subclasses, so it goes all the way down the chain of inheritance.

Parameters

subclass<Merb::ControllerExceptions::Base>

The Exception class that is inheriting from Merb::ControllerExceptions::Base

:api: public

# File lib/merb-core/controller/exceptions.rb, line 220
def inherited(subclass)
  # don't set the constant yet - any class methods will be called after self.inherited
  # unless self.status = ... is set explicitly, the status code will be inherited
  register_status_code(subclass, self.status) if self.status?
end
status() click to toggle source

Get the actual status-code for an Exception class.

As usual, this can come from a constant upwards in the inheritance chain.

Returns

Fixnum

The status code of this exception.

:api: public

# File lib/merb-core/controller/exceptions.rb, line 174
def status
  const_get(:STATUS) rescue 0
end
Also aliased as: to_i
status=(num) click to toggle source

Set the actual status-code for an Exception class.

If possible, set the STATUS constant, and update any previously registered (inherited) status-code.

Parameters

num<~to_i>

The status code

Returns

(Integer, nil)

The status set on this exception, or nil if a status was already set.

:api: private

# File lib/merb-core/controller/exceptions.rb, line 191
def status=(num)
  unless self.status?
    register_status_code(self, num)
    self.const_set(:STATUS, num.to_i)
  end
end
status?() click to toggle source

See if a status-code has been defined (on self explicitly).

Returns

Boolean

Whether a status code has been set

:api: private

# File lib/merb-core/controller/exceptions.rb, line 204
def status?
  self.const_defined?(:STATUS)
end
to_i()
Alias for: status

Private Class Methods

register_status_code(klass, code) click to toggle source

Register the status-code for an Exception class.

Parameters

num<~to_i>

The status code

:api: privaate

# File lib/merb-core/controller/exceptions.rb, line 234
def register_status_code(klass, code)
  name = self.to_s.split('::').last.snake_case
  STATUS_CODES[name.to_sym] = code.to_i
end

Public Instance Methods

status() click to toggle source

Returns

Integer

The status-code of the error.

@overridable :api: plugin

# File lib/merb-core/controller/exceptions.rb, line 160
def status; self.class.status; end
Also aliased as: to_i
to_i()
Alias for: status