module Roda::RodaPlugins::DefaultStatus

  1. lib/roda/plugins/default_status.rb

The default_status plugin accepts a block which should return a response status integer. This integer will be used as the default response status (usually 200) if the body has been written to, and you have not explicitly set a response status.

Example:

# Use 201 default response status for all requests
plugin :default_status do
  201
end

Methods

Public Class

  1. configure

Public Class methods

configure(app, &block)
[show source]
   # File lib/roda/plugins/default_status.rb
18 def self.configure(app, &block)
19   raise RodaError, "default_status plugin requires a block" unless block
20   if check_arity = app.opts.fetch(:check_arity, true)
21     # RODA4: Remove support for :check_arity, default to false behavior
22     unless block.arity == 0
23       if check_arity == :warn
24         RodaPlugins.warn "Arity mismatch in block passed to plugin :default_status. Expected Arity 0, but arguments required for #{block.inspect}"
25       end
26       b = block
27       block = lambda{instance_exec(&b)} # Fallback
28     end
29   end
30   app::RodaResponse.send(:define_method, :default_status, &block)
31 end