Class: Docker_Sync::WatchStrategy::Fswatch

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

Instance Method Summary collapse

Methods included from Execution

#threadexec

Constructor Details

#initialize(sync_name, options) ⇒ Fswatch

Returns a new instance of Fswatch.



12
13
14
15
# File 'lib/docker_sync/watch_strategy/fswatch.rb', line 12

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

Instance Method Details

#cleanObject



24
25
# File 'lib/docker_sync/watch_strategy/fswatch.rb', line 24

def clean
end

#runObject



17
18
19
# File 'lib/docker_sync/watch_strategy/fswatch.rb', line 17

def run
  watch
end

#stopObject



21
22
# File 'lib/docker_sync/watch_strategy/fswatch.rb', line 21

def stop
end

#watchObject



27
28
29
30
31
32
33
34
# File 'lib/docker_sync/watch_strategy/fswatch.rb', line 27

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

  @watch_thread = threadexec(cmd, "Sync #{@sync_name}", :blue)
end

#watch_optionsObject



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

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'])
  args.push(" | xargs -I -n1 thor sync:sync -n #{@sync_name} --config='#{@options['config_path']}'")
end

#watch_threadObject



47
48
49
# File 'lib/docker_sync/watch_strategy/fswatch.rb', line 47

def watch_thread
  return @watch_thread
end