-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add importer configuration for creator and file_path
`RecordImporter` needs to know which `User` to treat as the creator for imported objects, and where on the file system to look for referenced file names. These configuration options are added to `.env`, `config/importer.yml`, and `Importer.config`. They are passed to `RecordImporter` by default on creation. This work could be extended to allow overriding the configuration in the import rake task by allowing that task to build a custom `RecordImporter`. For now, the supporeted configuration is through `.env`. Connected to #170.
- Loading branch information
Tom Johnson
committed
Jan 25, 2018
1 parent
e760f47
commit 0172498
Showing
5 changed files
with
60 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,28 @@ | ||
# frozen_string_literal: true | ||
class Importer < Darlingtonia::Importer | ||
def initialize(parser:, record_importer: MahoniaRecordImporter.new) | ||
## | ||
# @return [Hash<Symbol, Object>] | ||
def self.config | ||
Rails.application.config_for(:importer) | ||
end | ||
|
||
def initialize(parser:, record_importer: default_record_importer) | ||
super | ||
end | ||
|
||
def config | ||
self.class.config | ||
end | ||
|
||
private | ||
|
||
def default_creator | ||
User | ||
.first_or_create!(email: config['username'], password: config['password']) | ||
end | ||
|
||
def default_record_importer | ||
MahoniaRecordImporter.new(creator: default_creator, | ||
file_path: config['file_path']) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
--- | ||
development: | ||
username: <%= ENV['IMPORTER_USER'] %> | ||
password: <%= ENV['IMPORTER_USER_PASS'] %> | ||
file_path: <%= ENV['IMPORTER_FILE_PATH'] %> | ||
|
||
test: | ||
username: <%= ENV['IMPORTER_USER'] %> | ||
password: <%= ENV['IMPORTER_USER_PASS'] %> | ||
file_path: <%= ENV['IMPORTER_FILE_PATH'] %> | ||
|
||
production: | ||
username: <%= ENV['IMPORTER_USER'] %> | ||
password: <%= ENV['IMPORTER_USER_PASS'] %> | ||
file_path: <%= ENV['IMPORTER_FILE_PATH'] %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters