Class: Dotpack::Runner
- Inherits:
-
Object
- Object
- Dotpack::Runner
- Defined in:
- lib/dotpack/runner.rb
Constant Summary collapse
Class Method Summary collapse
Instance Method Summary collapse
- #flavor(f) ⇒ Object
- #flavor!(f) ⇒ Object
- #flavor?(f) ⇒ Boolean
- #flavor_present?(f) ⇒ Boolean
- #pack(path) ⇒ Object
- #pack_recurse(path) ⇒ Object
- #start(package) ⇒ Object
Class Method Details
.clear ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 |
# 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 |
Instance Method Details
#flavor(f) ⇒ Object
75 76 77 78 |
# 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) ⇒ Object
84 85 86 87 88 |
# File 'lib/dotpack/runner.rb', line 84 def flavor!(f) v = flavor(f) return nil if v == '' v end |
#flavor?(f) ⇒ Boolean
71 72 73 |
# File 'lib/dotpack/runner.rb', line 71 def flavor?(f) !!flavor(f) end |
#flavor_present?(f) ⇒ Boolean
80 81 82 |
# File 'lib/dotpack/runner.rb', line 80 def flavor_present?(f) return !!flavor! end |
#pack(path) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# 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.(LOCAL_DIR + '/' + target), sym) @links.puts sym end end |
#pack_recurse(path) ⇒ Object
62 63 64 65 66 67 68 69 |
# 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 |