Class: SyncStage::Worker

Inherits:
Object
  • Object
show all
Defined in:
lib/sync_stage.rb

Instance Method Summary collapse

Constructor Details

#initialize(cfg) ⇒ Worker

Returns a new instance of Worker.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/sync_stage.rb', line 9

def initialize(cfg)
  s = Time.now
  Dir.chdir(cfg.app) do
    if !File.exist?('sync_stage.yml')
      if ! cfg.init
        puts "Directory not initialized - try argument --init or see --help"
        exit 1
      end
      if cfg.init
        create_example_config(cfg.app)
      end
    else
      read_config
    end
  end
  if cfg.explain
    explain(cfg.restore)
    exit 0
  end
  if cfg.run
    run(cfg.restore)
  end
  duration = Time.now - s
  puts "synced data \nfrom #{@config[:source].fetch(:host)} to #{@config[:destination].fetch(:host)} \n
  done in #{duration.ceil} seconds."
end