The custom_block_results plugin allows you to specify handling for different block results. By default, Roda
only supports nil, false, and string block results, but using this plugin, you can support other block results.
For example, if you wanted to support returning Integer block results, and have them set the response status code, you could do:
plugin :custom_block_results handle_block_result Integer do |result| response.status_code = result end route do |r| 200 end
The expected use case for this is to customize behavior by class, but matching uses ===, so it is possible to use non-class objects that respond to === appropriately.
Note that custom block result handling only occurs if the types are not handled by Roda
itself. You cannot use this to modify the handling of nil, false, or string results.
Classes and Modules
Public Class methods
configure(app)
[show source]
# File lib/roda/plugins/custom_block_results.rb 33 def self.configure(app) 34 app.opts[:custom_block_results] ||= {} 35 end