Module: Roda::RodaPlugins::Delegate
- Defined in:
- lib/roda/plugins/delegate.rb
Overview
The delegate plugin allows you to easily setup instance methods in the scope of the route block that call methods on the related request, response, or class which may offer a simpler API in some cases. Roda doesn’t automatically setup such delegate methods because it pollutes the application’s method namespace, but this plugin allows the user to do so.
Here’s an example based on the README’s initial example, using the request_delegate method to simplify the DSL:
plugin :delegate
request_delegate :root, :on, :is, :get, :post, :redirect
route do |r|
# GET / request
root do
redirect "/hello"
end
# /hello branch
on "hello" do
# GET /hello/world request
get "world" do
"Hello world!"
end
# /hello request
is do
# GET /hello request
get do
"Hello!"
end
# POST /hello request
post do
puts "Someone said hello!"
redirect
end
end
end
end
Defined Under Namespace
Modules: ClassMethods