0
@@ -79,6 +79,72 @@ module Halcyon
0
self.env['REQUEST_METHOD'].downcase.to_sym
0
+ # Returns the name of the controller in path form.
0
+ def self.controller_name
0
+ @controller_name ||= self.name.to_const_path
0
+ # Returns the name of the controller in path form.
0
+ self.class.controller_name
0
+ # Generates a URL based on the given name and passed
0
+ # options. Used with named routes and resources:
0
+ # url(:users) # => "/users"
0
+ # url(:admin_permissons) # => "/admin/permissions"
0
+ # url(:user, @user) # => "/users/1"
0
+ # Based on the identical method of Merb's controller.
0
+ def url(name, rparams={})
0
+ Halcyon::Application::Router.generate(name, rparams,
0
+ { :controller => controller_name,
0
+ # Responds with the correct status and body specified.
0
+ # * +state+ a snake-case symbol of the status (ie, <tt>:not_found</tt>,
0
+ # <tt>:unprocessable_entity</tt>, or <tt>:forbidden</tt>)
0
+ # * +body+ the response body (if the default is insufficient)
0
+ # class Foos < Application
0
+ # if (foo = Foo[params[:id]])
0
+ # The above example is the same as <tt>raise NotFound.new</tt>.
0
+ # If the state specified is not found, it will
0
+ # <tt>raise ServiceUnavailable.new</tt> (a <tt>503</tt> error). The error
0
+ # is then logged along with the backtrace.
0
+ def status(state, body = nil)
0
+ raise Halcyon::Exceptions.const_get(state.to_s.camel_case.to_sym).new(body)
0
+ self.logger.error "Invalid status #{state.inspect} specified."
0
+ self.logger.error "Backtrace:\n" << e.backtrace.join("\n\t")
0
+ raise Halcyon::Exceptions::ServiceUnavailable.new
0
+ alias_method :error, :status
0
# Formats message into the standard success response hash, with a status of
0
# 200 (the standard success response).
0
# +body+ the body of the response
0
@@ -129,35 +195,6 @@ module Halcyon
0
alias_method :missing, :not_found
0
- # Returns the name of the controller in path form.
0
- def self.controller_name
0
- @controller_name ||= self.name.to_const_path
0
- # Returns the name of the controller in path form.
0
- self.class.controller_name
0
- # Generates a URL based on the given name and passed
0
- # options. Used with named routes and resources:
0
- # url(:users) # => "/users"
0
- # url(:admin_permissons) # => "/admin/permissions"
0
- # url(:user, @user) # => "/users/1"
0
- # Based on the identical method of Merb's controller.
0
- def url(name, rparams={})
0
- Halcyon::Application::Router.generate(name, rparams,
0
- { :controller => controller_name,
Comments
No one has commented yet.