Exception: Merb::ControllerExceptions::Base

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

Overview

Base class for error codes used in Merb::ControllerExceptions.

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.



210
211
212
213
214
# File 'merb-core/lib/merb-core/controller/exceptions.rb', line 210

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

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



168
169
170
# File 'merb-core/lib/merb-core/controller/exceptions.rb', line 168

def status
  const_get(:STATUS) rescue 0
end

.status=(num) ⇒ Integer?

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.



184
185
186
187
188
189
# File 'merb-core/lib/merb-core/controller/exceptions.rb', line 184

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



196
197
198
# File 'merb-core/lib/merb-core/controller/exceptions.rb', line 196

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

Instance Method Details

#statusInteger

Returns The status-code of the error.

Overridable:



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

def status; self.class.status; end

#to_iInteger

Returns The status-code of the error.

Overridable:



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

def status; self.class.status; end