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



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

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

.nameObject

Returns

String

The snake cased name of the class without the namespace.



113
114
115
# File 'lib/merb-core/controller/exceptions.rb', line 113

def name
  self.to_s.split('::').last.snake_case
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.



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

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



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

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)


147
148
149
# File 'lib/merb-core/controller/exceptions.rb', line 147

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

Instance Method Details

#nameObject

Returns

String

The snake cased name of the error without the namespace.



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

def name; self.class.name; end

#statusObject

Returns

Integer

The status-code of the error.



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

def status; self.class.status; end

#to_iObject

Returns

Integer

The status-code of the error.



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

def status; self.class.status; end