Sha256: 9601f20d0c79adc7fc2f418137ded323a6564fbefeb7405db36e1f84d2b44cbc

Contents?: true

Size: 653 Bytes

Versions: 2

Compression:

Stored size: 653 Bytes

Contents

$:.unshift File.dirname(__FILE__)

require 'rack_interface/route'

class Usher
  module Interface
    class RackInterface
      
      Request = Struct.new(:path, :method)
      
      def initialize
        @routes = Usher.new
      end
      
      def add(path, options = {})
        @routes.add_route(path, options)
      end

      def reset!
        @routes.reset!
      end

      def call(env)
        response = @routes.recognize(Request.new(env['REQUEST_URI'], env['REQUEST_METHOD']))
        env['usher.params'] = response.params.inject({}){|h,(k,v)| h[k]=v; h }
        response.path.route.params.first.call(env)
      end

    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
joshbuddy-usher-0.3.2 lib/usher/interface/rack_interface.rb
joshbuddy-usher-0.3.3 lib/usher/interface/rack_interface.rb