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



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

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



78
79
80
81
# File 'lib/docker-sync/sync_process.rb', line 78

def clean
  @sync_strategy.clean
  @watch_strategy.clean
end

#get_host_ipObject



64
65
66
# File 'lib/docker-sync/sync_process.rb', line 64

def get_host_ip
  return 'localhost'
end

#runObject



68
69
70
71
# File 'lib/docker-sync/sync_process.rb', line 68

def run
  @sync_strategy.run
  @watch_strategy.run
end

#set_sync_strategyObject



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

def set_sync_strategy
  if @options.key?('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
        @sync_strategy = Docker_Sync::SyncStrategy::Rsync.new(@sync_name, @options)
    end
  else
    @sync_strategy = Docker_Sync::SyncStrategy::Rsync.new(@sync_name, @options)
  end
end

#set_watch_strategyObject



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/docker-sync/sync_process.rb', line 47

def set_watch_strategy
  if @options.key?('watch_strategy')
    case @options['watch_strategy']
      when 'fswatch'
        @watch_strategy = Docker_Sync::WatchStrategy::Fswatch.new(@sync_name, @options)
      when 'disable'
        @watch_strategy = Docker_Sync::WatchStrategy::Dummy.new(@sync_name, @options)
      when 'dummy'
        @watch_strategy = Docker_Sync::WatchStrategy::Dummy.new(@sync_name, @options)
      else
        @watch_strategy = Docker_Sync::WatchStrategy::Fswatch.new(@sync_name, @options)
    end
  else
    @watch_strategy = Docker_Sync::WatchStrategy::Fswatch.new(@sync_name, @options)
  end
end

#stopObject



73
74
75
76
# File 'lib/docker-sync/sync_process.rb', line 73

def stop
  @sync_strategy.stop
  @watch_strategy.stop
end

#syncObject



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

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

#watchObject



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

def watch
  @watch_strategy.run
end

#watch_threadObject



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

def watch_thread
  return @watch_strategy.watch_thread
end