Class: Brut::FrontEnd::RouteHook
- Inherits:
-
Object
- Object
- Brut::FrontEnd::RouteHook
- 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.
Direct Known Subclasses
Brut::FrontEnd::RouteHooks::AgeFlash, Brut::FrontEnd::RouteHooks::CSPNoInlineScripts, Brut::FrontEnd::RouteHooks::CSPNoInlineStylesOrScripts, Brut::FrontEnd::RouteHooks::LocaleDetection, Brut::FrontEnd::RouteHooks::SetupRequestContext
Instance Method Summary collapse
-
#after ⇒ URI|Brut::FrontEnd::HttpStatus|false|true|nil
Subclasses should implement this if they intend to be used as after hooks.
-
#before ⇒ URI|Brut::FrontEnd::HttpStatus|false|true|nil
Subclasses should implement this if they intend to be used as before hooks.
-
#continue ⇒ Object
Return this to continue the hook.
Methods included from Brut::Framework::Errors
Methods included from HandlingResults
Instance Method Details
#after ⇒ URI|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 URIBrut::FrontEnd::HttpStatus
- the request will be terminated with this statusfalse
- the request is terminated with a 500true
ornil
- the request will continue to the next hook or to the browser. Use #continue if this is what you want to happen
42 43 44 |
# File 'lib/brut/front_end/route_hook.rb', line 42 def after abstract_method! end |
#before ⇒ URI|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 URIBrut::FrontEnd::HttpStatus
- the request will be terminated with this statusfalse
- the request is terminated with a 500true
ornil
- the request will continue to the next hook or to the route handler. Use #continue if this is what you want to happen
27 28 29 |
# File 'lib/brut/front_end/route_hook.rb', line 27 def before abstract_method! end |
#continue ⇒ Object
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 |