Exception: Merb::ControllerExceptions::Base
- Defined in:
- lib/merb-core/controller/exceptions.rb
Overview
:doc:
Direct Known Subclasses
ClientError, Informational, Redirection, ServerError, Successful
Class Method Summary collapse
-
.inherited(subclass) ⇒ Object
Registers any subclasses with status codes for easy lookup by set_status in Merb::Controller.
-
.status ⇒ Object
(also: to_i)
Get the actual status-code for an Exception class.
-
.status=(num) ⇒ Object
Set the actual status-code for an Exception class.
-
.status? ⇒ Boolean
See if a status-code has been defined (on self explicitly).
Instance Method Summary collapse
-
#status ⇒ Object
Returns Integer:: The status-code of the error.
-
#to_i ⇒ Object
Returns Integer:: The status-code of the error.
Class Method Details
.inherited(subclass) ⇒ Object
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
220 221 222 223 224 |
# 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 ⇒ Object Also known as: to_i
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
174 175 176 |
# File 'lib/merb-core/controller/exceptions.rb', line 174 def status const_get(:STATUS) rescue 0 end |
.status=(num) ⇒ Object
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
191 192 193 194 195 196 |
# 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? ⇒ Boolean
See if a status-code has been defined (on self explicitly).
Returns
- Boolean
-
Whether a status code has been set
:api: private
204 205 206 |
# File 'lib/merb-core/controller/exceptions.rb', line 204 def status? self.const_defined?(:STATUS) end |
Instance Method Details
#status ⇒ Object
Returns
- Integer
-
The status-code of the error.
:api: plugin
160 |
# File 'lib/merb-core/controller/exceptions.rb', line 160 def status; self.class.status; end |
#to_i ⇒ Object
Returns
- Integer
-
The status-code of the error.
:api: plugin
161 |
# File 'lib/merb-core/controller/exceptions.rb', line 161 def status; self.class.status; end |