class Csb::Handler

Public Class Methods

call(template, source = nil) click to toggle source
# File lib/csb/handler.rb, line 10
    def self.call(template, source = nil)
      source ||= template.source

      <<~RUBY
        csv = ::Csb::Template.new(
          utf8_bom: ::Csb.configuration.utf8_bom,
          streaming: ::Csb.configuration.streaming,
        )
        #{source}
        controller.send(:send_file_headers!, type: 'text/csv', filename: csv.filename)
        if csv.streaming?
          response.headers['Cache-Control'] = 'no-cache'
          response.headers['X-Accel-Buffering'] = 'no'
          # SEE: https://github.com/rack/rack/issues/1619
          if Gem::Version.new('2.2.0') <= Gem::Version.new(Rack::RELEASE)
            response.headers['Last-Modified'] = '0'
          end
        end
        csv.build
      RUBY
    end