Module: Roda::RodaPlugins::RouteBlockArgs
- Defined in:
- lib/roda/plugins/route_block_args.rb
Overview
The route_block_args plugin lets you customize what arguments are passed to
the route block. So if you have an application that always needs access
to the response, the params, the env, or the session, you can use
this plugin so that any of those can be arguments to the route block.
Example:
class App < Roda
plugin :route_block_args do
[request, request.params, response]
end
route do |r, params, res|
r.post do
artist = Artist.create(name: params['name'].to_s)
res.status = 201
artist.id.to_s
end
end
end
This plugin will be no longer ship with Roda starting in Roda 4. Users are encouraged to switch to defining local variables at the top of the route block instead of using this plugin.
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Class Method Details
.configure(app, &block) ⇒ Object
32 33 34 35 36 37 |
# File 'lib/roda/plugins/route_block_args.rb', line 32 def self.configure(app, &block) app.instance_exec do define_roda_method(:_roda_route_block_args, 0, &block) route(&@raw_route_block) if @raw_route_block end end |