class Guard::Sync
Public Class Methods
new(watchers = [], options = {})
click to toggle source
Calls superclass method
# File lib/guard/sync.rb, line 6 def initialize(watchers = [], options = {}) super @options = { :run_on_start => false, :archive => false, :recursive => true, :compress => true, :permissions => true, :delete => false, :src => '.', :verbose => false, :quiet => true }.merge options update end
Public Instance Methods
run_all()
click to toggle source
# File lib/guard/sync.rb, line 26 def run_all UI.info "#{@action}d #{@options[:include]}" `#{@command}` if @opts end
run_on_additions(paths)
click to toggle source
# File lib/guard/sync.rb, line 31 def run_on_additions paths @action = "create" @options[:exclude] = '*' @options[:include] = paths.to_s[1..-2] @options[:delete] = false update run_all end
run_on_changes(paths)
click to toggle source
# File lib/guard/sync.rb, line 40 def run_on_changes paths @action = "modifie" @options[:exclude] = '*' @options[:include] = paths.to_s[1..-2] @options[:delete] = false update run_all end
run_on_modifications(paths)
click to toggle source
# File lib/guard/sync.rb, line 49 def run_on_modifications paths run_on_changes paths end
run_on_removals(paths)
click to toggle source
# File lib/guard/sync.rb, line 53 def run_on_removals paths @action = "remove" @options[:exclude] = '*' @options[:include] = paths.to_s[1..-2] @options[:delete] = true update run_all end
start()
click to toggle source
# File lib/guard/sync.rb, line 22 def start run_all if @options[:run_on_start] end
Private Instance Methods
get_combined_path(array, num)
click to toggle source
# File lib/guard/sync.rb, line 115 def get_combined_path array, num path = '' array.each_with_index do |folder, i| path << "#{folder}/" break if i == num end unless array.length < num path end
update()
click to toggle source
# File lib/guard/sync.rb, line 64 def update begin update_options update_command rescue :MissingOptions => e UI.info "Guard::Sync did not run successfully: #{e}" end end
update_command()
click to toggle source
# File lib/guard/sync.rb, line 73 def update_command raise :MissingOptions, "Missing either :src, :host, or :dest" unless @options[:src] and @options[:host] and @options[:dest] @command = "rsync #{@opts} #{@options[:src]} #{@options[:host]}:#{@options[:dest]}" end
update_options()
click to toggle source
# File lib/guard/sync.rb, line 78 def update_options opt_list = [] long_opts = [] opt_list.push('a') if @options[:archive] opt_list.push('r') if @options[:recursive] opt_list.push('p') if @options[:permissions] opt_list.push('z') if @options[:compress] opt_list.push('v') if @options[:verbose] opt_list.push('q') if @options[:quiet] include_paths = @options[:include] include_paths = include_paths[1..-2] if include_paths split_paths = include_paths.split('/') if include_paths joined_paths = [] if split_paths.kind_of?(Array) included_paths = [] split_paths.each_with_index do |path, index| combined_path = get_combined_path split_paths, index included_paths << "--include=#{combined_path.chop}" end joined_paths = included_paths.join(" ") end long_opts.push('--del') if @options[:delete] long_opts.push(joined_paths) if @options[:include] and joined_paths long_opts.push("--exclude=#{@options[:exclude]}") if @options[:exclude] raise :MissingOptions, "No options to pass to rsync" unless opt_list != [] @opts = '-'+opt_list.reduce { |a,b| a + b } long_opts = long_opts.reduce { |a,b| a + ' ' + b } @opts = @opts + " #{long_opts}" if long_opts end