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.



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/roda/plugins/halt.rb', line 41

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

  super()
end