Class: Lexicon::Common::Production::FileLoader
- Inherits:
-
Object
- Object
- Lexicon::Common::Production::FileLoader
- Defined in:
- lib/lexicon/common/production/file_loader.rb
Instance Method Summary collapse
-
#initialize(shell:, database_url:) ⇒ FileLoader
constructor
A new instance of FileLoader.
- #load_archive(archive) ⇒ Boolean
- #load_file(data_file) ⇒ Boolean
- #load_sql(file) ⇒ Boolean
Constructor Details
#initialize(shell:, database_url:) ⇒ FileLoader
Returns a new instance of FileLoader.
9 10 11 12 |
# File 'lib/lexicon/common/production/file_loader.rb', line 9 def initialize(shell:, database_url:) @shell = shell @database_url = database_url end |
Instance Method Details
#load_archive(archive) ⇒ Boolean
28 29 30 31 32 33 34 |
# File 'lib/lexicon/common/production/file_loader.rb', line 28 def load_archive(archive) shell.execute <<~BASH cat '#{archive}' | gzip -d | psql '#{database_url}' BASH true end |
#load_file(data_file) ⇒ Boolean
16 17 18 19 20 21 22 23 24 |
# File 'lib/lexicon/common/production/file_loader.rb', line 16 def load_file(data_file) if data_file.basename.to_s =~ /\.sql\z/ load_sql(data_file) elsif data_file.basename.to_s =~ /\.sql\.gz\z/ load_archive(data_file) else raise StandardError.new("Unknown file type: #{data_file.basename}") end end |
#load_sql(file) ⇒ Boolean
38 39 40 41 42 43 44 |
# File 'lib/lexicon/common/production/file_loader.rb', line 38 def load_sql(file) shell.execute <<~BASH echo psql '#{database_url}' < '#{file}' BASH true end |