class BreezyPDFLite::Interceptor
Intercept
a Rack request, determining if the app's response should be intercepted or simply returned
Attributes
app[R]
env[R]
Public Class Methods
new(app, env)
click to toggle source
# File lib/breezy_pdf_lite/interceptor.rb, line 9 def initialize(app, env) @app = app @env = env end
Public Instance Methods
call()
click to toggle source
# 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
Private Instance Methods
app_response()
click to toggle source
# File lib/breezy_pdf_lite/interceptor.rb, line 24 def app_response @app_response ||= app.call(doctored_env) end
app_response_body()
click to toggle source
# File lib/breezy_pdf_lite/interceptor.rb, line 36 def app_response_body if app_response[2].respond_to?(:join) app_response[2].join elsif app_response[2].respond_to?(:each) content = [] app_response[2].each { |part| content << part } content.join else app_response[2] end end
app_response_headers()
click to toggle source
# File lib/breezy_pdf_lite/interceptor.rb, line 32 def app_response_headers @app_response_headers ||= app_response[1] end
app_response_status()
click to toggle source
# File lib/breezy_pdf_lite/interceptor.rb, line 28 def app_response_status @app_response_status ||= app_response[0].to_i end
doctored_env()
click to toggle source
# File lib/breezy_pdf_lite/interceptor.rb, line 49 def doctored_env env.dup.tap do |hash| hash["HTTP_ACCEPT"] = "text/html" hash["PATH_INFO"] = path end end
path()
click to toggle source
# File lib/breezy_pdf_lite/interceptor.rb, line 56 def path env["PATH_INFO"].gsub(/\.pdf/, "") end