Class: Hanami::Static
- Inherits:
-
Rack::Static
- Object
- Rack::Static
- Hanami::Static
- Defined in:
- lib/hanami/static.rb
Overview
Constant Summary collapse
- PATH_INFO =
'PATH_INFO'.freeze
- PUBLIC_DIRECTORY =
Hanami.public_directory.join('**', '*').to_s.freeze
- URL_SEPARATOR =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
'/'.freeze
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.
13 14 15 16 |
# File 'lib/hanami/static.rb', line 13 def initialize(app) super(app, root: Hanami.public_directory, header_rules: _header_rules) @sources = _sources_from_applications end |
Instance Method Details
#call(env) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/hanami/static.rb', line 18 def call(env) path = env[PATH_INFO] prefix, config = @sources.find { |p, _| path.start_with?(p) } if prefix && config original = config.sources.find(path.sub(prefix, '')) end if can_serve(path, original) super else precompile(original, config) ? call(env) : @app.call(env) end end |