Module: Roda::RodaPlugins::DefaultStatus

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

Overview

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

Class Method Summary collapse

Class Method Details

.configure(app, &block) ⇒ Object

Raises:



18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/roda/plugins/default_status.rb', line 18

def self.configure(app, &block)
  raise RodaError, "default_status plugin requires a block" unless block
  if check_arity = app.opts.fetch(:check_arity, true)
    unless block.arity == 0
      if check_arity == :warn
        RodaPlugins.warn "Arity mismatch in block passed to plugin :default_status. Expected Arity 0, but arguments required for #{block.inspect}"
      end
      b = block
      block = lambda{instance_exec(&b)} # Fallback
    end
  end
  app::RodaResponse.send(:define_method, :default_status, &block)
end