Class: Miron::RequestFetcher

Inherits:
Object
  • Object
show all
Defined in:
lib/miron/request_fetcher.rb

Instance Method Summary collapse

Constructor Details

#initialize(request, mironfile) ⇒ RequestFetcher

Returns a new instance of RequestFetcher


3
4
5
6
7
# File 'lib/miron/request_fetcher.rb', line 3

def initialize(request, mironfile)
  @request = Miron::Request.new(request)
  @mironfile = mironfile
  @response = Miron::Response.new
end

Instance Method Details

#fetch_responseResponse

Returns the newly created Miron::Response

Returns:


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

def fetch_response
  miron_response = nil
  @mironfile.middleware.each do |middleware|
    middleware_response = middleware.call(@request, @response)
    miron_response = middleware_response if middleware_response.is_a?(Miron::Response)
  end

  return miron_response unless miron_response.nil?

  app_response = @mironfile.app.call(@request, @response)
  miron_response = app_response if app_response.is_a?(Miron::Response)
  miron_response
end