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



175
176
177
178
179
# File 'lib/merb-core/controller/exceptions.rb', line 175

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.



138
139
140
# File 'lib/merb-core/controller/exceptions.rb', line 138

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



150
151
152
153
154
155
# File 'lib/merb-core/controller/exceptions.rb', line 150

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 the a status code has been set

Returns:

  • (Boolean)


161
162
163
# File 'lib/merb-core/controller/exceptions.rb', line 161

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

Instance Method Details

#statusObject

Returns

Integer

The status-code of the error.



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

def status; self.class.status; end

#to_iObject

Returns

Integer

The status-code of the error.



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

def status; self.class.status; end