Class: Docker_Sync::WatchStrategy::Fswatch
- Inherits:
-
Object
- Object
- Docker_Sync::WatchStrategy::Fswatch
- Includes:
- Execution, Thor::Shell
- Defined in:
- lib/docker-sync/watch_strategy/fswatch.rb
Instance Method Summary collapse
- #clean ⇒ Object
- #get_sync_cli_call ⇒ Object
-
#initialize(sync_name, options) ⇒ Fswatch
constructor
A new instance of Fswatch.
- #run ⇒ Object
- #stop ⇒ Object
- #watch ⇒ Object
- #watch_options ⇒ Object
- #watch_thread ⇒ Object
Methods included from Execution
Constructor Details
#initialize(sync_name, options) ⇒ Fswatch
Returns a new instance of Fswatch.
16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/docker-sync/watch_strategy/fswatch.rb', line 16 def initialize(sync_name, ) @sync_name = sync_name @options = @events_to_watch = %w(AttributeModified Created Link MovedFrom MovedTo Renamed Removed Updated) begin Preconditions::fswatch_available rescue Exception => e say_status 'error', e., :red exit 1 end end |
Instance Method Details
#clean ⇒ Object
36 37 |
# File 'lib/docker-sync/watch_strategy/fswatch.rb', line 36 def clean end |
#get_sync_cli_call ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/docker-sync/watch_strategy/fswatch.rb', line 62 def get_sync_cli_call sync_command = 'thor sync:' case @options['cli_mode'] when 'docker-sync' say_status 'ok','Forcing cli mode docker-sync',:yellow if @options['verbose'] sync_command = 'docker-sync ' when 'thor' say_status 'ok','Forcing cli mode thor',:yellow if @options['verbose'] sync_command = 'thor sync:' else # 'auto' or any other, try to guss say_status 'ok','Cli mode is auto, selecting .. ',:white if @options['verbose'] exec_name = File.basename($PROGRAM_NAME) if exec_name != 'thor' sync_command = 'docker-sync ' else say_status 'warning', 'Called user thor, not docker-sync* wise, assuming dev mode, using thor', :yellow end say_status 'ok',".. #{sync_command}",:white if @options['verbose'] end # append the actual operation return "#{sync_command}sync" end |
#run ⇒ Object
29 30 31 |
# File 'lib/docker-sync/watch_strategy/fswatch.rb', line 29 def run watch end |
#stop ⇒ Object
33 34 |
# File 'lib/docker-sync/watch_strategy/fswatch.rb', line 33 def stop end |
#watch ⇒ Object
39 40 41 42 43 44 45 46 47 |
# File 'lib/docker-sync/watch_strategy/fswatch.rb', line 39 def watch args = 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_options ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/docker-sync/watch_strategy/fswatch.rb', line 49 def args = [] unless @options['watch_excludes'].nil? args = @options['watch_excludes'].map { |pattern| "--exclude='#{pattern}'" } + args end args.push('-orIE') args.push(@events_to_watch.map { |pattern| "--event #{pattern}" }) args.push(@options['watch_args']) if @options.key?('watch_args') args.push(@options['src']) sync_command = get_sync_cli_call args.push(" | xargs -I -n1 #{sync_command} -n #{@sync_name} --config='#{@options['config_path']}'") end |
#watch_thread ⇒ Object
85 86 87 |
# File 'lib/docker-sync/watch_strategy/fswatch.rb', line 85 def watch_thread return @watch_thread end |