Module: Roda::RodaPlugins::Halt::RequestMethods

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

Instance Method Summary collapse

Instance Method Details

#halt(*res) ⇒ Object

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



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/roda/plugins/halt.rb', line 72

def halt(*res)
  case res.length
  when 0 # do nothing
  when 1
    case v = res[0]
    when Integer
      response.status = v
    when Array
      throw :halt, v
    else
      if result = block_result_body(v)
        response.write(result)
      else
        raise Roda::RodaError, "singular argument given to #halt not handled: #{v.inspect}"
      end
    end
  when 2
    resp = response
    resp.status = res[0]
    resp.write(block_result_body(res[1]))
  when 3
    resp = response
    resp.status = res[0]
    resp.headers.merge!(res[1])
    resp.write(block_result_body(res[2]))
  else
    raise Roda::RodaError, "too many arguments given to #halt (accepts 0-3, received #{res.length})"
  end

  super()
end