Sha256: eb4604eaff3c7baa4f2e0a4fa94d38a597e036023b8edaf8c966563927e38c78

Contents?: true

Size: 847 Bytes

Versions: 10

Compression:

Stored size: 847 Bytes

Contents

# encoding: utf-8

require "rango/router"
require "rango/rack/request"

module Rango
  module Mini
    extend self # so you can run Rango::Mini.app
    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
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
rango-0.2.6 lib/rango/mini.rb
rango-0.2.5.1 lib/rango/mini.rb
rango-0.2.4.1 lib/rango/mini.rb
rango-0.2.3 lib/rango/mini.rb
rango-0.2.1 lib/rango/mini.rb
rango-0.2.1.pre lib/rango/mini.rb
rango-0.2 lib/rango/mini.rb
rango-0.1.1.3 lib/rango/mini.rb
rango-0.1.1.2.11 lib/rango/mini.rb
rango-0.2.pre lib/rango/mini.rb