Class: Hanami::Assets::Static Private
- Defined in:
- lib/hanami/assets/static.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Serve static assets in development environments (development, test).
While serving static assets is a role delegated in production to web servers (like Nginx), in development it’s rare to use a web server. For this purpose Hanami enables this Rack middleware to serve static assets in development (and test) phase.
The other important role of ‘Hanami::Assets::Static` is to lazily compile (or copy) the assets into the public directory.
Constant Summary collapse
- PATH_INFO =
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.
'PATH_INFO'.freeze
Constants inherited from Static
Static::HEADER_RULES, Static::MAX_AGE, Static::URL_PREFIX
Instance Method Summary collapse
- #call(env) ⇒ Object private
-
#initialize(app) ⇒ Static
constructor
private
A new instance of Static.
Constructor Details
#initialize(app) ⇒ Static
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of Static.
35 36 37 38 |
# File 'lib/hanami/assets/static.rb', line 35 def initialize(app) super(app, header_rules: []) @sources = _sources_from_applications end |
Instance Method Details
#call(env) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
42 43 44 45 46 47 48 49 50 51 |
# File 'lib/hanami/assets/static.rb', line 42 def call(env) asset = Assets::Asset.new(@sources, env[PATH_INFO]) if serve?(asset) precompile(asset) serve(env, asset) else @app.call(env) end end |