Module: Rango::Mini

Extended by:
Mini
Included in:
Mini, MiniRender
Defined in:
lib/rango/mini.rb

Instance Method Summary collapse

Instance Method Details

#app(&block) ⇒ Object

Raises:

  • (ArgumentError)


9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/rango/mini.rb', line 9

def app(&block)
  raise ArgumentError, "Block is required" unless block_given?
  lambda do |env|
    Rango::Router.set_rack_env(env)
    request = Rango::Request.new(env)
    response = Rack::Response.new
    body = block.call(request, response)
    # TODO: check how rack test if object is stringable, probably not this way
    raise ArgumentError, "It has to return a valid rack body, #{body.inspect} returned" unless body.respond_to?(:each) || body.is_a?(String)
    response.write(body)
    array = response.finish
    [array[0], array[1], body] # we don't want to have Rack::Response instance instead body, it's mess!
  end
end