Class: SparkEngine::StaticAssets
- Inherits:
-
Object
- Object
- SparkEngine::StaticAssets
- Defined in:
- lib/spark_engine/middleware.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, path, index: 'index', headers: {}, engine_name: nil) ⇒ StaticAssets
constructor
A new instance of StaticAssets.
Constructor Details
#initialize(app, path, index: 'index', headers: {}, engine_name: nil) ⇒ StaticAssets
Returns a new instance of StaticAssets.
6 7 8 9 10 |
# File 'lib/spark_engine/middleware.rb', line 6 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
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/spark_engine/middleware.rb', line 12 def call(env) req = Rack::Request.new env prefix = File.join Rails.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 |