Class: Brut::FrontEnd::RouteHook

Inherits:
Object
  • Object
show all
Includes:
Brut::Framework::Errors, HandlingResults
Defined in:
lib/brut/front_end/route_hook.rb

Overview

Base class for all route hooks. A route hook must implement either before or after and can be used via Brut::Framework::App.before or Brut::Framework::App.after.

A route hook differs from Middleware in to ways:

  • A route hook has a rich structured return type that is more expressive that Rack's array, however less powerful.
  • A route hook can be injected with session and request information via RequestContext. This allows your route hooks to easily access information like the currently-logged-in user, session, flash, or query string parameters.

Note that while a route hook can be used as both a before and an after, state will not be shared.

Instance Method Summary collapse

Methods included from Brut::Framework::Errors

#abstract_method!, #bug!

Methods included from HandlingResults

#http_status, #redirect_to

Instance Method Details

#afterURI|Brut::FrontEnd::HttpStatus|false|true|nil

Subclasses should implement this if they intend to be used as after hooks. The method parameters that the subclass uses will determine what information is avaiable.

The return type determines what happens:

  • URI - the browser will be redirected to this URI
  • Brut::FrontEnd::HttpStatus - the request will be terminated with this status
  • false - the request is terminated with a 500
  • true or nil - the request will continue to the next hook or to the browser. Use #continue if this is what you want to happen

Returns:



42
43
44
# File 'lib/brut/front_end/route_hook.rb', line 42

def after
  abstract_method!
end

#beforeURI|Brut::FrontEnd::HttpStatus|false|true|nil

Subclasses should implement this if they intend to be used as before hooks. The method parameters that the subclass uses will determine what information is avaiable.

The return type determines what happens:

  • URI - the browser will be redirected to this URI
  • Brut::FrontEnd::HttpStatus - the request will be terminated with this status
  • false - the request is terminated with a 500
  • true or nil - the request will continue to the next hook or to the route handler. Use #continue if this is what you want to happen

Returns:



27
28
29
# File 'lib/brut/front_end/route_hook.rb', line 27

def before
  abstract_method!
end

#continueObject

Return this to continue the hook. This is preferred over true or nil as it communicates the intent of what should happen



47
# File 'lib/brut/front_end/route_hook.rb', line 47

def continue = true