Sha256: d0508ddc53f69d6691694f0fce613d0d2ebfab0f467662108c57b9d987bb9bed

Contents?: true

Size: 837 Bytes

Versions: 1

Compression:

Stored size: 837 Bytes

Contents

# frozen_string_literal: true

require 'csb/template'

module Csb
  class Handler
    class_attribute :default_format
    self.default_format = :csv

    def self.call(template, source = nil)
      source ||= template.source

      <<~RUBY
        csv = ::Csb::Template.new(
          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
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
csb-0.12.0 lib/csb/handler.rb