Class Merb::ControllerExceptions::Base
In: merb-core/lib/merb-core/controller/exceptions.rb
Parent: StandardError

Methods

Public Class methods

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

[Source]

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

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

[Source]

     # File merb-core/lib/merb-core/controller/exceptions.rb, line 174
174:         def status
175:           const_get(:STATUS) rescue 0
176:         end

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

[Source]

     # File merb-core/lib/merb-core/controller/exceptions.rb, line 191
191:         def status=(num)
192:           unless self.status?
193:             register_status_code(self, num)
194:             self.const_set(:STATUS, num.to_i)
195:           end
196:         end

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

Returns

Boolean:Whether a status code has been set

:api: private

[Source]

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

Private Class methods

Register the status-code for an Exception class.

Parameters

num<~to_i>:The status code

:api: privaate

[Source]

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

Public Instance methods

Returns

Integer:The status-code of the error.

@overridable :api: plugin

[Source]

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

Alias for status

to_i()

Alias for status

[Validate]