Class: ContentPreview::Router::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/content-preview/router.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path = File.expand_path('../router/routes.yml', __FILE__)) ⇒ Base

Returns a new instance of Base.



10
11
12
# File 'lib/content-preview/router.rb', line 10

def initialize(path = File.expand_path('../router/routes.yml', __FILE__))
  @routes = YAML.load_file path
end

Class Method Details

.call(*args) ⇒ Object



27
28
29
# File 'lib/content-preview/router.rb', line 27

def call *args
  new.call *args
end

Instance Method Details

#call(env) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/content-preview/router.rb', line 14

def call(env)
  path = env['PATH_INFO']

  until @routes.has_key? path do
    path = path.rpartition('/').first
    path = '/' if path.empty?
  end

  class_name = @routes[path].capitalize
  Handlers.const_get(class_name).call env
end