Class: Rack::Zippy::AssetServer
- Inherits:
-
Object
- Object
- Rack::Zippy::AssetServer
- Defined in:
- lib/rack-zippy.rb
Instance Attribute Summary collapse
-
#static_middleware ⇒ Object
readonly
Returns the value of attribute static_middleware.
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, path, max_age_fallback: :day) ⇒ AssetServer
constructor
A new instance of AssetServer.
Constructor Details
#initialize(app, path, max_age_fallback: :day) ⇒ AssetServer
Returns a new instance of AssetServer.
21 22 23 24 25 26 27 28 29 |
# File 'lib/rack-zippy.rb', line 21 def initialize(app, path, max_age_fallback: :day) assert_path_valid path cache_control = cache_control(max_age_fallback) @app = app blank_app = ->(env) { } @static_middleware = ::ActionDispatch::Static.new(blank_app, path, cache_control) end |
Instance Attribute Details
#static_middleware ⇒ Object (readonly)
Returns the value of attribute static_middleware.
16 17 18 |
# File 'lib/rack-zippy.rb', line 16 def static_middleware @static_middleware end |
Instance Method Details
#call(env) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/rack-zippy.rb', line 31 def call(env) path_info = env[PATH_INFO] return not_found_response if illegal_path?(path_info) if try_static?(path_info) static_response = static_middleware.call(env) end if static_response after_static_responds(env, static_response) else @app.call(env) end end |