Class: Togo::Static
- Inherits:
-
Object
- Object
- Togo::Static
- Defined in:
- lib/togo/dispatch/dispatch.rb
Overview
Dispatch
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, options = {}) ⇒ Static
constructor
A new instance of Static.
Constructor Details
#initialize(app, options = {}) ⇒ Static
Returns a new instance of Static.
204 205 206 207 208 209 210 |
# File 'lib/togo/dispatch/dispatch.rb', line 204 def initialize(app, ={}) @app = app @path_prefix = [:path_prefix] || '' @urls = [:urls] || ["/favicon.ico"] root = [:root] || Dir.pwd @file_server = Rack::File.new(root) end |
Instance Method Details
#call(env) ⇒ Object
212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 |
# File 'lib/togo/dispatch/dispatch.rb', line 212 def call(env) path = env["PATH_INFO"] path = path.gsub(Regexp.new("^#{@path_prefix}"), '') if @path_prefix > '' unless @urls.kind_of? Hash can_serve = @urls.any? { |url| path.index(url) == 0 } else can_serve = @urls.key? path end if can_serve env["PATH_INFO"] = (@urls.kind_of?(Hash) ? @urls[path] : path) @file_server.call(env) else @app.call(env) end end |