class Dotpack::Runner
Constants
- LOCAL_DIR
Public Class Methods
clear()
click to toggle source
# File lib/dotpack/runner.rb, line 9 def self.clear FileUtils.rm_rf(LOCAL_DIR) if File.exist? Config::BASE_DIR + '/links' File.foreach(Config::BASE_DIR + '/links') do |line| line.chomp! if File.exist?(line) || File.symlink?(line) File.unlink(line) end end File.unlink(Config::BASE_DIR + '/links') end end
Public Instance Methods
flavor(f)
click to toggle source
# File lib/dotpack/runner.rb, line 75 def flavor(f) f = f.to_s if f.is_a? Symbol Config.flavor(f) end
flavor!(f)
click to toggle source
# File lib/dotpack/runner.rb, line 84 def flavor!(f) v = flavor(f) return nil if v == '' v end
flavor?(f)
click to toggle source
# File lib/dotpack/runner.rb, line 71 def flavor?(f) !!flavor(f) end
flavor_present?(f)
click to toggle source
# File lib/dotpack/runner.rb, line 80 def flavor_present?(f) return !!flavor! end
pack(path)
click to toggle source
# File lib/dotpack/runner.rb, line 32 def pack(path) return unless File.exist? path target = path.split('/').map do |p| if p[0] == '_' '.' + p[1..-1] else p end end target = target.join "/" sym = Dir.home + '/' + target if File.directory? path FileUtils.mkdir_p sym FileUtils.mkdir_p LOCAL_DIR + '/' + target else if path.include? '/' pack(File.dirname path) end if File.exist?(sym) || File.symlink?(sym) File.unlink sym end erb = ERB.new(File.read(path)) result = erb.result(binding) File.write LOCAL_DIR + '/' + target, result File.symlink(File.expand_path(LOCAL_DIR + '/' + target), sym) @links.puts sym end end
pack_recurse(path)
click to toggle source
# File lib/dotpack/runner.rb, line 62 def pack_recurse(path) return unless File.exist? path if File.directory? path Dir[path + '/**/*'].each {|x| pack(x)} else pack(path) end end
start(package)
click to toggle source
# File lib/dotpack/runner.rb, line 22 def start(package) @links = File.open(Config::BASE_DIR + '/links', "a") pwd = Dir.pwd Dir.chdir package.path instance_eval File.read(package.path + "/Dotpackfile") Dir.chdir pwd @links.close @links = nil end