Class: Docker_Sync::WatchStrategy::Fswatch

Inherits:
Object
  • Object
show all
Includes:
Execution, Preconditions, Thor::Shell
Defined in:
lib/docker_sync/watch_strategy/fswatch.rb

Instance Method Summary collapse

Methods included from Preconditions

#check_all_preconditions, #docker_available, #docker_running, #docker_sync_available, #fswatch_available, #rsync_available, #unison_available

Methods included from Execution

#threadexec

Constructor Details

#initialize(sync_name, options) ⇒ Fswatch

Returns a new instance of Fswatch.



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/docker_sync/watch_strategy/fswatch.rb', line 16

def initialize(sync_name, options)
  @sync_name = sync_name
  @options = options

  begin
    fswatch_available
  rescue Exception => e
    say_status 'error', e.message, :red
    exit 1
  end
end

Instance Method Details

#cleanObject



35
36
# File 'lib/docker_sync/watch_strategy/fswatch.rb', line 35

def clean
end

#runObject



28
29
30
# File 'lib/docker_sync/watch_strategy/fswatch.rb', line 28

def run
  watch
end

#stopObject



32
33
# File 'lib/docker_sync/watch_strategy/fswatch.rb', line 32

def stop
end

#watchObject



38
39
40
41
42
43
44
45
46
# File 'lib/docker_sync/watch_strategy/fswatch.rb', line 38

def watch
  args = watch_options
  say_status 'success', "Starting to watch #{@options['src']} - Press CTRL-C to stop", :green
  cmd = 'fswatch ' + args.join(' ')
  say_status 'command', cmd, :white if @options['verbose']

  # run a thread here, since it is blocking
  @watch_thread = threadexec(cmd, "Sync #{@sync_name}", :blue)
end

#watch_optionsObject



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/docker_sync/watch_strategy/fswatch.rb', line 48

def watch_options
  args = []
  unless @options['watch_excludes'].nil?
    args = @options['watch_excludes'].map { |pattern| "--exclude='#{pattern}'" } + args
  end
  args.push('-orIE')
  args.push(@options['watch_args']) if @options.key?('watch_args')
  args.push(@options['src'])

  sync_command = 'thor sync:sync'
  begin
    docker_sync_available
    sync_command = 'docker-sync sync'
  rescue Exception => e
    say_status 'warning', 'docker-sync not available, assuming dev mode, using thor', :yellow
    puts e.message
    sync_command = 'thor sync:sync'
  end
  args.push(" | xargs -I -n1 #{sync_command} -n #{@sync_name} --config='#{@options['config_path']}'")
end

#watch_threadObject



69
70
71
# File 'lib/docker_sync/watch_strategy/fswatch.rb', line 69

def watch_thread
  return @watch_thread
end