Class: Cyborg::StaticAssets
- Inherits:
-
Object
- Object
- Cyborg::StaticAssets
- Defined in:
- lib/cyborg/middleware.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, path, cache_control = nil, engine_name: nil) ⇒ StaticAssets
constructor
A new instance of StaticAssets.
Constructor Details
#initialize(app, path, cache_control = nil, engine_name: nil) ⇒ StaticAssets
Returns a new instance of StaticAssets.
25 26 27 28 29 |
# File 'lib/cyborg/middleware.rb', line 25 def initialize(app, path, index: 'index', headers: {}, engine_name: nil) @app = app @engine_name = engine_name @file_handler = ActionDispatch::FileHandler.new(path, index: index, headers: headers) end |
Instance Method Details
#call(env) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/cyborg/middleware.rb', line 31 def call(env) req = Rack::Request.new env prefix = File.join Application.config.assets.prefix, @engine_name if req.get? || req.head? path = req.path_info.chomp('/'.freeze) if path.start_with? prefix path = path.remove /\A#{prefix}\// if match = @file_handler.match?(path) req.path_info = match return @file_handler.serve(req) end end end @app.call(req.env) end |