Class: Chewy::Railtie::RequestStrategy

Inherits:
Object
  • Object
show all
Defined in:
lib/chewy/railtie.rb

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ RequestStrategy

Returns a new instance of RequestStrategy.



8
9
10
# File 'lib/chewy/railtie.rb', line 8

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/chewy/railtie.rb', line 12

def call(env)
  # For Rails applications in `api_only` mode, the `assets` config isn't present
  if Rails.application.config.respond_to?(:assets) && env['PATH_INFO'].start_with?(Rails.application.config.assets.prefix)
    @app.call(env)
  else
    if Chewy.logger && @request_strategy != Chewy.request_strategy
      Chewy.logger.info("Chewy request strategy is `#{Chewy.request_strategy}`")
    end
    @request_strategy = Chewy.request_strategy
    Chewy.strategy(Chewy.request_strategy) { @app.call(env) }
  end
end