Class: Primer::Router

Inherits:
Sinatra::Base
  • Object
show all
Defined in:
lib/primer/route_set.rb

Defined Under Namespace

Classes: Request

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ Router

Returns a new instance of Router.



33
34
35
36
# File 'lib/primer/route_set.rb', line 33

def initialize(path)
  @request = Request.new(path)
  @original_params = indifferent_hash
end

Class Method Details

.new(*args) ⇒ Object

Circumvent the fact that Sinatra::Base.new creates a Rack stack



29
30
31
# File 'lib/primer/route_set.rb', line 29

def self.new(*args)
  Class.instance_method(:new).bind(self).call(*args)
end

Instance Method Details

#evaluateObject



38
39
40
41
42
43
44
45
46
47
48
# File 'lib/primer/route_set.rb', line 38

def evaluate
  routes = self.class.routes['GET']
  catch(:halt) {
    routes.each do |pattern, keys, conditions, block|
      process_route(pattern, keys, conditions) do
        throw(:halt, instance_eval(&block))
      end
    end
    raise RouteNotFound.new("No route match found for key #{@request.path_info}")
  }
end