Class: Geordi::DumpLoader
- Inherits:
-
Object
- Object
- Geordi::DumpLoader
show all
- Includes:
- Interaction
- Defined in:
- lib/geordi/dump_loader.rb
Instance Method Summary
collapse
#announce, #fail, #note, #note_cmd, #prompt, #strip_heredoc, #success, #warn
Constructor Details
Returns a new instance of DumpLoader.
10
11
12
|
# File 'lib/geordi/dump_loader.rb', line 10
def initialize(file)
@dump_file = file
end
|
Instance Method Details
#development_database_config ⇒ Object
Also known as:
config
14
15
16
17
18
19
|
# File 'lib/geordi/dump_loader.rb', line 14
def development_database_config
require 'yaml'
@config ||= YAML.safe_load(ERB.new(File.read('config/database.yml')).result)
@config['development']
end
|
#dump_file ⇒ Object
44
45
46
47
48
49
50
51
52
53
|
# File 'lib/geordi/dump_loader.rb', line 44
def dump_file
@dump_file ||= begin
dumps_glob = File.join(File.expand_path('~'), 'dumps', '*.dump')
available_dumps = Dir.glob(dumps_glob).sort
HighLine.new.choose(*available_dumps) do ||
.hidden('') { raise 'Abort.' }
end
end
end
|
#load ⇒ Object
55
56
57
58
59
60
|
# File 'lib/geordi/dump_loader.rb', line 55
def load
note 'Source file: ' + dump_file
source_command = send("#{config['adapter']}_command")
Util.system! source_command, fail_message: "An error occured loading #{File.basename(dump_file)}"
end
|
#mysql_command ⇒ Object
Also known as:
mysql2_command
22
23
24
25
26
27
28
29
30
31
|
# File 'lib/geordi/dump_loader.rb', line 22
def mysql_command
command = 'mysql --silent'
command << ' -p' << config['password'].to_s if config['password']
command << ' -u' << config['username'].to_s if config['username']
command << ' --port=' << config['port'].to_s if config['port']
command << ' --host=' << config['host'].to_s if config['host']
command << ' --default-character-set=utf8'
command << ' ' << config['database'].to_s
command << ' < ' << dump_file
end
|
#postgresql_command ⇒ Object
34
35
36
37
38
39
40
41
42
|
# File 'lib/geordi/dump_loader.rb', line 34
def postgresql_command
ENV['PGPASSWORD'] = config['password']
command = 'pg_restore --no-owner --clean'
command << ' --username=' << config['username'].to_s if config['username']
command << ' --port=' << config['port'].to_s if config['port']
command << ' --host=' << config['host'].to_s if config['host']
command << ' --dbname=' << config['database'].to_s
command << ' ' << dump_file
end
|