Class: Gitenv::Runner

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

Instance Method Summary collapse

Constructor Details

#initializeRunner

Returns a new instance of Runner.



9
10
11
12
# File 'lib/gitenv.rb', line 9

def initialize
  @home = File.expand_path '~'
  @config_file = File.join @home, '.gitenv.rb'
end

Instance Method Details

#runObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/gitenv.rb', line 14

def run

  @dsl = DSL.new
  @dsl.instance_eval File.open(@config_file, 'r').read, @config_file

  action = ARGV.shift || 'info'

  puts
  puts "gitenv v#{VERSION}"
  puts "configuration #{@config_file}"
  puts
  case action
  when 'info'
    puts Paint["Listing current state", :bright, :bold]
  when 'update'
    puts Paint["Creating missing links", :blue, :bold]
  end

  @dsl.symlinks.each do |link|

    link_file_path = File.join @home, link[:file]
    real_file = link[:source] || link[:file]
    real_file_path = File.join File.expand_path(@dsl.repository), real_file

    msg = %/#{Paint[link_file_path, :cyan]} -> #{real_file_path}/
    data = analyze link_file_path, real_file_path

    case action
    when 'info'
      puts %/#{info_mark data}#{msg}   #{info_msg data}/
    when 'update'
      unless File.exists? link_file_path
        File.symlink real_file_path, link_file_path
      end
      puts %/#{update_mark data}#{msg}   #{update_msg data}/
    else
      raise "No such action #{action}"
    end
  end

  puts
end