Class: Static

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ Static

Returns a new instance of Static.



6
7
8
9
10
# File 'lib/scaffold/lib/middleware/static.rb', line 6

def initialize(app)
  @app = app
  @root = :public
  @file_server = FileServer.new(root)
end

Instance Attribute Details

#appObject (readonly)

Returns the value of attribute app.



4
5
6
# File 'lib/scaffold/lib/middleware/static.rb', line 4

def app
  @app
end

#file_serverObject (readonly)

Returns the value of attribute file_server.



4
5
6
# File 'lib/scaffold/lib/middleware/static.rb', line 4

def file_server
  @file_server
end

#rootObject (readonly)

Returns the value of attribute root.



4
5
6
# File 'lib/scaffold/lib/middleware/static.rb', line 4

def root
  @root
end

Instance Method Details

#call(env) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/scaffold/lib/middleware/static.rb', line 12

def call(env)
  req = Rack::Request.new(env)
  path = req.path

  if can_serve?(path)
    res = file_server.call(env)
  else
    res = app.call(env)
  end

  res
end