Class: Raport::Report::Renderer
- Inherits:
-
Object
- Object
- Raport::Report::Renderer
- Defined in:
- app/services/raport/report/renderer.rb
Instance Attribute Summary collapse
-
#report ⇒ Object
Returns the value of attribute report.
-
#tmpfile ⇒ Object
readonly
Returns the value of attribute tmpfile.
-
#view ⇒ Object
readonly
Returns the value of attribute view.
Instance Method Summary collapse
-
#initialize(report) ⇒ Renderer
constructor
A new instance of Renderer.
- #render ⇒ Object
Constructor Details
#initialize(report) ⇒ Renderer
Returns a new instance of Renderer.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'app/services/raport/report/renderer.rb', line 9 def initialize(report) @report = report @view ||= begin view = ActionView::Base.new view.view_paths = ActionController::Base.view_paths view.extend ApplicationHelper view end @tmpfile ||= begin tmpfile = Tempfile.new(report.tmp_filename) tmpfile.write(render_view) tmpfile end end |
Instance Attribute Details
#report ⇒ Object
Returns the value of attribute report.
5 6 7 |
# File 'app/services/raport/report/renderer.rb', line 5 def report @report end |
#tmpfile ⇒ Object (readonly)
Returns the value of attribute tmpfile.
7 8 9 |
# File 'app/services/raport/report/renderer.rb', line 7 def tmpfile @tmpfile end |
#view ⇒ Object (readonly)
Returns the value of attribute view.
7 8 9 |
# File 'app/services/raport/report/renderer.rb', line 7 def view @view end |
Instance Method Details
#render ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'app/services/raport/report/renderer.rb', line 24 def render begin report.activate report.file = tmpfile report.finish rescue => e report.last_error = [e., e.backtrace.join("\n")].join("\n") report.flop raise ensure tmpfile.close case tmpfile.class.name when 'Tempfile' then tmpfile.unlink when 'File' then File.unlink(tmpfile.path) end end end |