Class: Static
- Inherits:
-
Object
- Object
- Static
- Defined in:
- lib/static.rb
Instance Attribute Summary collapse
-
#app ⇒ Object
readonly
Returns the value of attribute app.
-
#file_server ⇒ Object
readonly
Returns the value of attribute file_server.
-
#root ⇒ Object
readonly
Returns the value of attribute root.
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app) ⇒ Static
constructor
A new instance of Static.
Constructor Details
#initialize(app) ⇒ Static
Returns a new instance of Static.
4 5 6 7 8 |
# File 'lib/static.rb', line 4 def initialize(app) @app = app @root = :public @file_server = FileServer.new(root) end |
Instance Attribute Details
#app ⇒ Object (readonly)
Returns the value of attribute app.
3 4 5 |
# File 'lib/static.rb', line 3 def app @app end |
#file_server ⇒ Object (readonly)
Returns the value of attribute file_server.
3 4 5 |
# File 'lib/static.rb', line 3 def file_server @file_server end |
#root ⇒ Object (readonly)
Returns the value of attribute root.
3 4 5 |
# File 'lib/static.rb', line 3 def root @root end |
Instance Method Details
#call(env) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/static.rb', line 10 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 |