lib/smarter_csv.rb in smarter_csv-1.11.0 vs lib/smarter_csv.rb in smarter_csv-1.11.1
- old
+ new
@@ -1,18 +1,22 @@
# frozen_string_literal: true
require "smarter_csv/version"
+require "smarter_csv/errors"
+
require "smarter_csv/file_io"
require "smarter_csv/options_processing"
require "smarter_csv/auto_detection"
require "smarter_csv/variables"
require 'smarter_csv/header_transformations'
require 'smarter_csv/header_validations'
require "smarter_csv/headers"
require "smarter_csv/hash_transformations"
+
require "smarter_csv/parse"
require "smarter_csv/writer"
+require "smarter_csv/smarter_csv"
# load the C-extension:
case RUBY_ENGINE
when 'ruby'
begin
@@ -47,6 +51,26 @@
-------------------------------------------------------------------------
BLOCK_COMMENT
end
# :nocov:
-require "smarter_csv/smarter_csv"
+
+module SmarterCSV
+ # SmarterCSV.generate(filename, options) do |csv_writer|
+ # MyModel.find_in_batches(batch_size: 100) do |batch|
+ # batch.pluck(:name, :description, :instructor).each do |record|
+ # csv_writer << record
+ # end
+ # end
+ # end
+ #
+ # rubocop:disable Lint/UnusedMethodArgument
+ def self.generate(filename, options = {}, &block)
+ raise unless block_given?
+
+ writer = Writer.new(filename, options)
+ yield writer
+ ensure
+ writer.finalize
+ end
+ # rubocop:enable Lint/UnusedMethodArgument
+end