Exception: Merb::ControllerExceptions::Base

Inherits:
StandardError
  • Object
show all
Defined in:
lib/merb-core/controller/exceptions.rb

Overview

:doc:

Class Method Summary collapse

Instance Method Summary collapse

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



217
218
219
220
221
# File 'lib/merb-core/controller/exceptions.rb', line 217

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

.statusObject 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.



171
172
173
# File 'lib/merb-core/controller/exceptions.rb', line 171

def status
  const_get(:STATUS) rescue 0
end

.status=(num) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

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.



188
189
190
191
192
193
# File 'lib/merb-core/controller/exceptions.rb', line 188

def status=(num)
  unless self.status?
    register_status_code(self, num)
    self.const_set(:STATUS, num.to_i)
  end
end

.status?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

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

Returns

Boolean

Whether a status code has been set

Returns:

  • (Boolean)


201
202
203
# File 'lib/merb-core/controller/exceptions.rb', line 201

def status?
  self.const_defined?(:STATUS)
end

Instance Method Details

#statusObject

Returns

Integer

The status-code of the error.



157
# File 'lib/merb-core/controller/exceptions.rb', line 157

def status; self.class.status; end

#to_iObject

Returns

Integer

The status-code of the error.



158
# File 'lib/merb-core/controller/exceptions.rb', line 158

def status; self.class.status; end