Class: RemoteDatabaseImporter::Operation
- Inherits:
-
Object
- Object
- RemoteDatabaseImporter::Operation
- Defined in:
- lib/remote_database_importer/operation.rb
Constant Summary collapse
- LOG_FILE =
"tmp/remote_database_importer.log"
Instance Attribute Summary collapse
-
#config ⇒ Object
Returns the value of attribute config.
-
#current_environment ⇒ Object
Returns the value of attribute current_environment.
Instance Method Summary collapse
- #environments ⇒ Object
- #import ⇒ Object
-
#initialize ⇒ Operation
constructor
A new instance of Operation.
- #select_environment ⇒ Object
Constructor Details
#initialize ⇒ Operation
Returns a new instance of Operation.
11 12 13 |
# File 'lib/remote_database_importer/operation.rb', line 11 def initialize @config = RemoteDatabaseImporter::Config.new.read_or_create_configfile end |
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config.
6 7 8 |
# File 'lib/remote_database_importer/operation.rb', line 6 def config @config end |
#current_environment ⇒ Object
Returns the value of attribute current_environment.
7 8 9 |
# File 'lib/remote_database_importer/operation.rb', line 7 def current_environment @current_environment end |
Instance Method Details
#environments ⇒ Object
15 16 17 |
# File 'lib/remote_database_importer/operation.rb', line 15 def environments config.fetch("environments") end |
#import ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/remote_database_importer/operation.rb', line 35 def import select_environment time_start = Time.now multi_spinner = TTY::Spinner::Multi.new("[:spinner] Import remote DB", format: :dots_3) tasks = create_tasks_and_spinners(multi_spinner) puts "Be aware, you may get asked for a password for the ssh or db connection" tasks.each do |task| task[:spinner].auto_spin task_execution_was_successful = system(task[:command]) return "Can't continue, following task failed: #{task[:command]} - checkout the logfile: #{LOG_FILE}" unless task_execution_was_successful task[:spinner].stop("... Done!") end puts seconds_to_human_readable_time(Time.now - time_start) end |
#select_environment ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/remote_database_importer/operation.rb', line 19 def select_environment if environments.size > 1 puts "Select the operation environment:" environments.map(&:keys).flatten.each_with_index do |env, index| puts "#{index} for #{env.capitalize}" end env = environments[$stdin.gets.chomp.to_i].values[0] raise "Environment couldn't be found!" if env.blank? @current_environment = env return end @current_environment = environments[0].values[0] end |