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



20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/docker-sync/sync_process.rb', line 20

def initialize(sync_name, options)
  defaults = {
      'verbose' => false,
      'sync_host_ip' => get_host_ip
  }
  @sync_name = sync_name
  @options = defaults.merge(options)
  @sync_strategy = nil
  @watch_strategy = nil
  set_sync_strategy
  set_watch_strategy
end

Instance Method Details

#cleanObject



71
72
73
74
# File 'lib/docker-sync/sync_process.rb', line 71

def clean
  @sync_strategy.clean
  @watch_strategy.clean
end

#get_host_ipObject



57
58
59
# File 'lib/docker-sync/sync_process.rb', line 57

def get_host_ip
  return '127.0.0.1'
end

#runObject



61
62
63
64
# File 'lib/docker-sync/sync_process.rb', line 61

def run
  @sync_strategy.run
  @watch_strategy.run
end

#set_sync_strategyObject



33
34
35
36
37
38
39
40
41
42
# File 'lib/docker-sync/sync_process.rb', line 33

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)
  else
    raise "Unknown sync_strategy #{@options['sync_strategy']}"
  end
end

#set_watch_strategyObject



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

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)
  else
    raise "Unknown watch_strategy #{@options['watch_strategy']}"
  end
end

#start_containerObject



81
82
83
# File 'lib/docker-sync/sync_process.rb', line 81

def start_container
  @sync_strategy.start_container
end

#stopObject



66
67
68
69
# File 'lib/docker-sync/sync_process.rb', line 66

def stop
  @sync_strategy.stop
  @watch_strategy.stop
end

#syncObject



76
77
78
79
# File 'lib/docker-sync/sync_process.rb', line 76

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

#watchObject



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

def watch
  @watch_strategy.run
end

#watch_forkObject



89
90
91
# File 'lib/docker-sync/sync_process.rb', line 89

def watch_fork
  return @watch_strategy.watch_fork
end

#watch_threadObject



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

def watch_thread
  return @watch_strategy.watch_thread
end