Sha256: 33ab776140aedf7b204417932b8244257865c516c06765d4d85eb7fa8f3b0d8f

Contents?: true

Size: 577 Bytes

Versions: 7

Compression:

Stored size: 577 Bytes

Contents

module Kontrol

  class Router
    
    def initialize(&block)
      @routes = []
      @map = {}

      instance_eval(&block) if block
    end

    def __find__(name)
      @map[name.to_sym]
    end

    def __recognize__(request)
      @routes.each do |route|
        if match = route.recognize(request)
          return route, match
        end
      end
      
      return nil
    end

    def method_missing(name, pattern, *args, &block)
      route = Route.new(name, pattern, args.first, block)
      
      @routes << route
      @map[name] = route
    end

  end

end

Version data entries

7 entries across 7 versions & 2 rubygems

Version Path
georgi-kontrol-0.2 lib/kontrol/router.rb
georgi-kontrol-0.3 lib/kontrol/router.rb
kontrol-0.4 lib/kontrol/router.rb
kontrol-0.3.3 lib/kontrol/router.rb
kontrol-0.3.2 lib/kontrol/router.rb
kontrol-0.3.1 lib/kontrol/router.rb
kontrol-0.3 lib/kontrol/router.rb