unison-watch/lib/unison/profile.rb

49 lines
997 B
Ruby
Raw Normal View History

2012-05-07 10:44:25 +00:00
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