Add interactor ImportAll
This commit is contained in:
parent
1ddd6be5d7
commit
4a7a273a31
3 changed files with 31 additions and 0 deletions
22
app/interactors/import_all.rb
Normal file
22
app/interactors/import_all.rb
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
class ImportAll
|
||||||
|
include Interactor
|
||||||
|
|
||||||
|
def dirname
|
||||||
|
@dirname ||= Pathname.new(context.dirname).realpath.freeze
|
||||||
|
end
|
||||||
|
|
||||||
|
def call
|
||||||
|
import 'LPR_PEOPLE_ALL.csv', ImportPerson
|
||||||
|
import 'LPR_CONTACTS_ALL.csv', ImportContact
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def import(filename, interactor)
|
||||||
|
CSV.read(dirname.join(filename), col_sep: ';').drop(1).each do |row|
|
||||||
|
interactor.call row: row
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -18,6 +18,8 @@ require 'sprockets/railtie'
|
||||||
# you've limited to :test, :development, or :production.
|
# you've limited to :test, :development, or :production.
|
||||||
Bundler.require(*Rails.groups)
|
Bundler.require(*Rails.groups)
|
||||||
|
|
||||||
|
require 'csv'
|
||||||
|
|
||||||
module Partynest
|
module Partynest
|
||||||
class Application < Rails::Application
|
class Application < Rails::Application
|
||||||
FILTER_PARAMS = %i[
|
FILTER_PARAMS = %i[
|
||||||
|
|
7
spec/interactors/import_all_spec.rb
Normal file
7
spec/interactors/import_all_spec.rb
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
require 'rails_helper'
|
||||||
|
|
||||||
|
RSpec.describe ImportAll do
|
||||||
|
pending "add some examples to (or delete) #{__FILE__}"
|
||||||
|
end
|
Reference in a new issue