Class: DotMe::Dsl

Inherits:
Object
  • Object
show all
Defined in:
lib/dotme/dsl.rb

Class Method Summary collapse

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args) ⇒ Object



32
33
34
35
36
37
38
39
40
# File 'lib/dotme/dsl.rb', line 32

def method_missing( name, *args )
  name = "_#{name}"
  if respond_to? name
    args.each_with_index do |arg,i|
      args[i] = arg.is_a?(String) ? arg.gsub( '~', Etc.getpwuid.dir ) : arg.map { |v| v.gsub( '~', Etc.getpwuid.dir ) }
    end
    send name.to_sym, *args
  end
end

Class Method Details

.run(filename) ⇒ Object



6
7
8
# File 'lib/dotme/dsl.rb', line 6

def self.run( filename )
  self.new.instance_eval( ::File.read(filename), filename )
end

Instance Method Details

#_backup(what, where) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/dotme/dsl.rb', line 10

def _backup( what, where )
  FileUtils.rm_rf where unless !::File.directory? where
  Dir.mkdir where, 0700

  what.each do |file|
    from = ::File.join Etc.getpwuid.dir, file
    unless file[0] != '.'
      file = file[1..-1]
    end 
    if File.exists? from
      puts "Backupping #{from} to #{where} ..."
      FileUtils.mv from, ::File.join( where, file ) 
    end
  end
end


26
27
28
29
30
# File 'lib/dotme/dsl.rb', line 26

def _link( what, where )
  puts "Symlinking #{what} to #{where} ..."
  what = File.absolute_path what
  File.symlink what, where
end

#git_clone(repo, where) ⇒ Object



42
43
44
# File 'lib/dotme/dsl.rb', line 42

def git_clone( repo, where )
  puts "GIT CLONE #{repo} #{where}"
end

#sh(cmd) ⇒ Object



46
47
48
# File 'lib/dotme/dsl.rb', line 46

def sh( cmd )
  system cmd
end