Module: DirSync

Defined in:
lib/dir_sync.rb,
lib/dir_sync/traverser.rb,
lib/dir_sync/change_resolver.rb,
lib/dir_sync/history_traverser.rb,
lib/dir_sync/change_log_file_system.rb

Defined Under Namespace

Classes: ChangeLogFileSystem, ChangeResolver, HistoryTraverser, Traverser

Class Method Summary collapse

Class Method Details

.drain(*paths) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/dir_sync.rb', line 21

def self.drain *paths
  if paths.empty?
    puts "usage: #{__FILE__} *scripts"
    puts "  Runs a set of single line commands one by one (so that you can interrupt and the script will resume)"
    exit 1
  end

  paths.each do |path|
    lines = File.readlines(path).map {|s| s.chomp.strip }.select {|s| !s.empty? and !s.start_with?('#')}

    loop do
      break if lines.empty?
      lines.shift.tap {|s| puts "> #{s}" }.tap {|s| puts `#{s}` }
      File.open("#{path}.tmp", 'w') {|f| f.puts lines.join "\n" }
      `mv #{path}.tmp #{path}`
    end
    `rm #{path}`
  end
end

.sync(name, *paths) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/dir_sync.rb', line 7

def self.sync name, *paths
  if paths.count < 2
    puts "usage: #{__FILE__} name directory1 directory2 ..."
    puts " set DEBUG for verbose output"
    exit 1
  end
  file_system = DirSync::ChangeLogFileSystem.new $stdout
  traversers = paths.map {|path| DirSync::Traverser.new path, file_system }
  history = DirSync::HistoryTraverser.new name
  resolver = DirSync::ChangeResolver.new history, *traversers
  loop { break unless resolver.iterate }
  history.close
end