diff --git a/bin/unison-watch b/bin/unison-watch index 6a1ec65..909ee8f 100755 --- a/bin/unison-watch +++ b/bin/unison-watch @@ -1,57 +1,11 @@ #!/usr/bin/env ruby -require 'bundler/setup' - require 'Qt4' require 'thread' require 'atomic' require 'thor' -class UnisonProfile - def self.process(profiles) - profiles.collect { |profile| new(profile) } - end - - def initialize(which) - @which = which - end - - def local_root - roots.find { |root| root[%r{^/}] } - end - - def roots - @roots ||= lines.find_all { |line| line[%r{^root}] }.collect { |line| value_of(line) } - end - - def lines - return @lines if @lines - - @lines = File.readlines(File.expand_path("~/.unison/#{@which}.prf")) - - includes = [] - - @lines.each do |line| - if file = line[%r{^include (.*)}, 1] - includes += File.readlines(File.expand_path("~/.unison/#{file}")) - end - end - - @lines += includes - end - - def paths - @paths ||= lines.find_all { |line| line[%r{^path}] }.collect { |line| value_of(line) } - end - - def paths_with_local_root - paths.collect { |path| File.join(local_root, path) } - end - - def value_of(line) - line[%r{=(.*)$}, 1].strip - end -end +require 'unison/profile' class UnisonWatcher < Qt::Application TRANSFER_LOG = '~/unison.log' @@ -74,7 +28,7 @@ class UnisonWatcher < Qt::Application end def processed_profiles - @processed_profiles ||= UnisonProfile.process(@profiles) + @processed_profiles ||= Unison::Profile.process(@profiles) end def watch diff --git a/lib/unison/profile.rb b/lib/unison/profile.rb new file mode 100644 index 0000000..83ca068 --- /dev/null +++ b/lib/unison/profile.rb @@ -0,0 +1,48 @@ +module Unison + class Profile + def self.process(profiles) + profiles.collect { |profile| new(profile) } + end + + def initialize(which) + @which = which + end + + def local_root + roots.find { |root| root[%r{^/}] } + end + + def roots + @roots ||= lines.find_all { |line| line[%r{^root}] }.collect { |line| value_of(line) } + end + + def lines + return @lines if @lines + + @lines = File.readlines(File.expand_path("~/.unison/#{@which}.prf")) + + includes = [] + + @lines.each do |line| + if file = line[%r{^include (.*)}, 1] + includes += File.readlines(File.expand_path("~/.unison/#{file}")) + end + end + + @lines += includes + end + + def paths + @paths ||= lines.find_all { |line| line[%r{^path}] }.collect { |line| value_of(line) } + end + + def paths_with_local_root + paths.collect { |path| File.join(local_root, path) } + end + + def value_of(line) + line[%r{=(.*)$}, 1].strip + end + end +end + diff --git a/unison-watch.gemfile b/unison-watch.gemfile new file mode 100644 index 0000000..e69de29