class GitFyncy::Synchronizer
Public Class Methods
new(background, extra_rsync_args)
click to toggle source
# File lib/git-fyncy/synchronizer.rb, line 11 def initialize(background, extra_rsync_args) remote, path = Repo.host_and_path_from_current_repo pexit 'A remote and path must be specified' unless path @background = background @logger = Logger.new background @remote = Remote.new @logger, remote, path, extra_rsync_args end
Public Instance Methods
listen()
click to toggle source
Listen to file changes, forking to the background first if background is true.
# File lib/git-fyncy/synchronizer.rb, line 25 def listen daemonize if @background @logger.log "GIT FYNCY: Listening @ #{Time.now.ctime}" relpath = method :relative_path files_to_remove = Set.new begin Listen.to!('.') do |modified, added, removed| begin self.sync rel_removed = removed.map(&relpath) files_to_remove.merge rel_removed files_to_remove.clear if @remote.rm files_to_remove rescue => e @logger.log e.inspect end end rescue SignalException exit 42 ensure @logger.log "\n" end end
sync()
click to toggle source
# File lib/git-fyncy/synchronizer.rb, line 19 def sync @remote.rsync Repo.git_aware_files end
Private Instance Methods
daemonize()
click to toggle source
# File lib/git-fyncy/synchronizer.rb, line 50 def daemonize pid = fork if pid # parent Process.detach pid exit 0 end end
relative_path(path)
click to toggle source
# File lib/git-fyncy/synchronizer.rb, line 58 def relative_path(path) path.slice! slashify(Dir.pwd) path end