Sha256: 1e29761dceac17591ab19ddbeeffca226d6ac5932dbe4fb445cd6b188c13e694

Contents?: true

Size: 887 Bytes

Versions: 8

Compression:

Stored size: 887 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(
          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
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
csb-0.7.0 lib/csb/handler.rb
csb-0.6.0 lib/csb/handler.rb
csb-0.5.1 lib/csb/handler.rb
csb-0.5.0 lib/csb/handler.rb
csb-0.4.0 lib/csb/handler.rb
csb-0.3.1 lib/csb/handler.rb
csb-0.3.0 lib/csb/handler.rb
csb-0.2.4 lib/csb/handler.rb