Class: PrintMapService
- Inherits:
-
Object
- Object
- PrintMapService
- Defined in:
- lib/print_map_service.rb
Instance Attribute Summary collapse
-
#create_job ⇒ Object
readonly
Returns the value of attribute create_job.
-
#worker ⇒ Object
readonly
Returns the value of attribute worker.
Instance Method Summary collapse
- #call(env) ⇒ Object
- #create_error_response(e) ⇒ Object
- #create_invalid_job_response(job) ⇒ Object
-
#initialize(opts = {}) ⇒ PrintMapService
constructor
A new instance of PrintMapService.
Constructor Details
Instance Attribute Details
#create_job ⇒ Object (readonly)
Returns the value of attribute create_job.
6 7 8 |
# File 'lib/print_map_service.rb', line 6 def create_job @create_job end |
#worker ⇒ Object (readonly)
Returns the value of attribute worker.
6 7 8 |
# File 'lib/print_map_service.rb', line 6 def worker @worker end |
Instance Method Details
#call(env) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/print_map_service.rb', line 13 def call(env) puts 'calling print map' job = create_job.call(Rack::Request.new(env).params) if job.valid? puts 'valid job' pdf = worker.do_job(job) puts 'rendering to client' # now stream the pdf to the client [ 200, { "Content-Type" => "application/pdf", "Content-Disposition" => "attachment; filename=\"#{job.title}.pdf\"" }, pdf.render ] else create_invalid_job_response(job) end rescue Exception => e create_error_response(e) end |
#create_error_response(e) ⇒ Object
43 44 45 46 47 48 |
# File 'lib/print_map_service.rb', line 43 def create_error_response(e) body = "An internal error occurred:\n#{e.}" puts 'failed to generate print map:' puts body [500, { "Content-Type" => "text/plain" }, body] end |
#create_invalid_job_response(job) ⇒ Object
36 37 38 39 40 41 |
# File 'lib/print_map_service.rb', line 36 def create_invalid_job_response(job) body = "Print map failed because of the following errors:\n#{job.errors..join("\n")}" puts 'failed to generate print map:' puts body [500, { "Content-Type" => "text/plain" }, body] end |