Module: BulkCsvParser

Defined in:
lib/bulk_csv_parser.rb,
lib/bulk_csv_parser/engine.rb,
lib/bulk_csv_parser/result.rb,
lib/bulk_csv_parser/storage.rb,
lib/bulk_csv_parser/version.rb,
lib/bulk_csv_parser/processor.rb,
lib/bulk_csv_parser/import_job.rb,
lib/bulk_csv_parser/configuration.rb,
app/mailers/bulk_csv_parser/import_mailer.rb,
lib/generators/bulk_csv_parser/install/install_generator.rb

Defined Under Namespace

Modules: Generators Classes: Configuration, Engine, ImportJob, ImportMailer, Processor, Result, Storage

Constant Summary collapse

VERSION =
"0.1.1"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.configurationObject



17
18
19
# File 'lib/bulk_csv_parser.rb', line 17

def configuration
  @configuration ||= Configuration.new
end

Class Method Details

.configure {|configuration| ... } ⇒ Object

Yields:



21
22
23
# File 'lib/bulk_csv_parser.rb', line 21

def configure
  yield(configuration)
end

.enqueue(file:, model:, find_by:, attributes:, **options) ⇒ Object

Stores the uploaded file (via BulkCsvParser::Storage -- Active Storage by default, so it lands on S3/GCS/Azure and any worker machine can read it back) then enqueues BulkCsvParser::ImportJob. file can be an ActionDispatch::Http::UploadedFile, Rack::Test::UploadedFile, or anything responding to #path.

Pass notify_email: "someone@example.com" to have ImportJob email the success/failure counts and per-row failure reasons once it's done.



38
39
40
41
42
43
44
45
46
47
48
# File 'lib/bulk_csv_parser.rb', line 38

def enqueue(file:, model:, find_by:, attributes:, **options)
  reference = Storage.store(file)

  ImportJob.perform_later(
    file_reference: reference,
    model: model.to_s,
    find_by: find_by,
    attributes: attributes,
    **options
  )
end

.import(**options) ⇒ Object

Synchronous import, runs in the current process/request.



26
27
28
# File 'lib/bulk_csv_parser.rb', line 26

def import(**options)
  Processor.new(**options).call
end