class Lexicon::Common::Production::FileLoader
Attributes
database_url[R]
@return [String]
shell[R]
@return [ShellExecutor]
Public Class Methods
new(shell:, database_url:)
click to toggle source
@param [ShellExecutor] shell @param [String] database_url
# File lib/lexicon/common/production/file_loader.rb, line 9 def initialize(shell:, database_url:) @shell = shell @database_url = database_url end
Public Instance Methods
load_archive(archive)
click to toggle source
@param [Pathname] archive @return [Boolean]
# 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)
click to toggle source
@param [Pathname] data_file @return [Boolean]
# 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)
click to toggle source
@param [Pathname] file @return [Boolean]
# 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