Class: BreezyPDFLite::Interceptor

Inherits:
Object
  • Object
show all
Defined in:
lib/breezy_pdf_lite/interceptor.rb

Overview

Intercept a Rack request, determining if the app’s response should be intercepted or simply returned

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app, env) ⇒ Interceptor

Returns a new instance of Interceptor.



9
10
11
12
# File 'lib/breezy_pdf_lite/interceptor.rb', line 9

def initialize(app, env)
  @app = app
  @env = env
end

Instance Attribute Details

#appObject (readonly)

Returns the value of attribute app.



7
8
9
# File 'lib/breezy_pdf_lite/interceptor.rb', line 7

def app
  @app
end

#envObject (readonly)

Returns the value of attribute env.



7
8
9
# File 'lib/breezy_pdf_lite/interceptor.rb', line 7

def env
  @env
end

Instance Method Details

#callObject



14
15
16
17
18
19
20
# File 'lib/breezy_pdf_lite/interceptor.rb', line 14

def call
  if (200..299).cover?(app_response_status) # Did the app respond well?
    Intercept::HTML.new(app_response_body).call # Try to return a PDF
  else
    app_response # Bad app response, just send respond with that
  end
end