Sha256: 48539e11839cbb5afc4938234ad17f041c4626f255ca1a52a6c072bcff0e776c

Contents?: true

Size: 689 Bytes

Versions: 3

Compression:

Stored size: 689 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'
        end
        csv.build
      RUBY
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
csb-0.2.2 lib/csb/handler.rb
csb-0.2.1 lib/csb/handler.rb
csb-0.2.0 lib/csb/handler.rb