Module: Roda::RodaPlugins::CustomBlockResults

Defined in:
lib/roda/plugins/custom_block_results.rb

Overview

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.

Defined Under Namespace

Modules: ClassMethods, RequestMethods

Class Method Summary collapse

Class Method Details

.configure(app) ⇒ Object



33
34
35
# File 'lib/roda/plugins/custom_block_results.rb', line 33

def self.configure(app)
  app.opts[:custom_block_results] ||= {}
end