module Roda::RodaPlugins::Halt::RequestMethods

  1. lib/roda/plugins/halt.rb

Methods

Public Instance

  1. halt

Public Instance methods

halt(*res)

Expand default halt method to handle status codes, headers, and bodies. See Halt.

[show source]
    # File lib/roda/plugins/halt.rb
 72 def halt(*res)
 73   case res.length
 74   when 0 # do nothing
 75   when 1
 76     case v = res[0]
 77     when Integer
 78       response.status = v
 79     when Array
 80       throw :halt, v
 81     else
 82       if result = block_result_body(v)
 83         response.write(result)
 84       else
 85         raise Roda::RodaError, "singular argument given to #halt not handled: #{v.inspect}"
 86       end
 87     end
 88   when 2
 89     resp = response
 90     resp.status = res[0]
 91     resp.write(block_result_body(res[1]))
 92   when 3
 93     resp = response
 94     resp.status = res[0]
 95     resp.headers.merge!(res[1])
 96     resp.write(block_result_body(res[2]))
 97   else
 98     raise Roda::RodaError, "too many arguments given to #halt (accepts 0-3, received #{res.length})"
 99   end
100 
101   super()
102 end