Class: Docker_Sync::SyncProcess

Inherits:
Object
  • Object
show all
Includes:
Thor::Shell
Defined in:
lib/docker-sync/sync_process.rb

Instance Method Summary collapse

Constructor Details

#initialize(sync_name, options) ⇒ SyncProcess

noinspection RubyStringKeysInHashInspection



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/docker-sync/sync_process.rb', line 24

def initialize(sync_name, options)
  @sync_name = sync_name

  defaults = {
      'verbose' => false,
  }

  # even if sync_host_ip is set, if it is set to auto, enforce the default
  if !options.key?('sync_host_ip') || options['sync_host_ip'] == 'auto' || options['sync_host_ip'] == ''
    options['sync_host_ip'] = get_host_ip_default
  end

  @options = defaults.merge(options)
  @sync_strategy = nil
  @watch_strategy = nil
  set_sync_strategy
  set_watch_strategy
end

Instance Method Details

#cleanObject



96
97
98
99
# File 'lib/docker-sync/sync_process.rb', line 96

def clean
  @sync_strategy.clean
  @watch_strategy.clean
end

#get_host_ip_defaultObject



73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/docker-sync/sync_process.rb', line 73

def get_host_ip_default
  return '127.0.0.1' if DockerSync::Preconditions::Strategy.instance.is_driver_docker_for_mac?

  if DockerSync::Preconditions::Strategy.instance.is_driver_docker_toolbox?
    cmd = 'docker-machine ip $(docker-machine active)'
    stdout, stderr, exit_status = Open3.capture3(cmd)
    unless exit_status.success?
      raise "Error getting sync_host_ip automatically, exit code #{$?.exitstatus} ... #{stderr}"
    end
    return stdout.gsub("\n",'')
  end
end

#runObject



86
87
88
89
# File 'lib/docker-sync/sync_process.rb', line 86

def run
  @sync_strategy.run
  @watch_strategy.run
end

#set_sync_strategyObject



43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/docker-sync/sync_process.rb', line 43

def set_sync_strategy
  case @options['sync_strategy']
  when 'rsync'
    @sync_strategy = Docker_Sync::SyncStrategy::Rsync.new(@sync_name, @options)
  when 'unison'
    @sync_strategy = Docker_Sync::SyncStrategy::Unison.new(@sync_name, @options)
  when 'native'
    @sync_strategy = Docker_Sync::SyncStrategy::Native.new(@sync_name, @options)
  when 'native_osx'
    @sync_strategy = Docker_Sync::SyncStrategy::NativeOsx.new(@sync_name, @options)
  else
    raise "Unknown sync_strategy #{@options['sync_strategy']}"
  end
end

#set_watch_strategyObject



58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/docker-sync/sync_process.rb', line 58

def set_watch_strategy
  case @options['watch_strategy']
  when 'fswatch'
    @watch_strategy = Docker_Sync::WatchStrategy::Fswatch.new(@sync_name, @options)
  when 'dummy'
    @watch_strategy = Docker_Sync::WatchStrategy::Dummy.new(@sync_name, @options)
  when 'unison'
    @watch_strategy = Docker_Sync::WatchStrategy::Unison.new(@sync_name, @options)
  when 'remotelogs'
    @watch_strategy = Docker_Sync::WatchStrategy::Remote_logs.new(@sync_name, @options)
  else
    raise "Unknown watch_strategy #{@options['watch_strategy']}"
  end
end

#start_containerObject



106
107
108
# File 'lib/docker-sync/sync_process.rb', line 106

def start_container
  @sync_strategy.start_container
end

#stopObject



91
92
93
94
# File 'lib/docker-sync/sync_process.rb', line 91

def stop
  @sync_strategy.stop
  @watch_strategy.stop
end

#syncObject



101
102
103
104
# File 'lib/docker-sync/sync_process.rb', line 101

def sync
  # TODO: probably use run here
  @sync_strategy.sync
end

#watchObject



110
111
112
# File 'lib/docker-sync/sync_process.rb', line 110

def watch
  @watch_strategy.run
end

#watch_forkObject



114
115
116
# File 'lib/docker-sync/sync_process.rb', line 114

def watch_fork
  return @watch_strategy.watch_fork
end

#watch_threadObject



118
119
120
# File 'lib/docker-sync/sync_process.rb', line 118

def watch_thread
  return @watch_strategy.watch_thread
end