Class: Sapp::Router

Inherits:
Object
  • Object
show all
Defined in:
lib/sapp/router.rb

Instance Method Summary collapse

Constructor Details

#initialize(&block) ⇒ Router

Returns a new instance of Router.



4
5
6
7
# File 'lib/sapp/router.rb', line 4

def initialize &block
  @apps = Array.new
  instance_eval(&block) if block
end

Instance Method Details

#appsObject



27
28
29
# File 'lib/sapp/router.rb', line 27

def apps
  @apps
end

#call(env) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/sapp/router.rb', line 9

def call env
  request = Rack::Request.new env
  found   = Array.new

  @apps.each do |a|
    path = a.run(request)
    found << path if path
  end

  begin
    duplicate_apps! if found.count > 1
  rescue => e
    puts e.message
  end

  found.any? ? found.first : [ 404, {}, ["Not found"] ]
end