Class: Vanilla::Static

Inherits:
Object
  • Object
show all
Defined in:
lib/vanilla/static.rb

Instance Method Summary collapse

Constructor Details

#initialize(app, root) ⇒ Static

Returns a new instance of Static.



6
7
8
9
# File 'lib/vanilla/static.rb', line 6

def initialize(app, root)
  @app = app
  @file_server = ::Rack::File.new(root)
end

Instance Method Details

#call(env) ⇒ Object



11
12
13
14
15
16
17
18
19
20
# File 'lib/vanilla/static.rb', line 11

def call(env)
  path   = env['PATH_INFO'].chomp('/')
  method = env['REQUEST_METHOD']

  if %w(GET HEAD).include?(method) && file_exist?(path)
    @file_server.call(env)
  else
    @app.call(env)
  end
end