Class: Pik::GemSync

Inherits:
Command show all
Includes:
BatchFileEditor
Defined in:
lib/pik/commands/gemsync_command.rb

Instance Attribute Summary

Attributes included from BatchFileEditor

#batch

Attributes inherited from Command

#config, #options, #output, #version

Instance Method Summary collapse

Methods included from BatchFileEditor

#close, #echo_ruby_version, #echo_running_with_ruby_version, #initialize, #set, #switch_gem_home_to, #switch_path_to, #update_gem_batch

Methods inherited from Command

#add_sigint_handler, aka, choose_from, clean_gem_batch, #close, cmd_name, #cmd_name, #create, #current_gem_bin_path, #current_version?, #default_gem_home, #delete_old_pik_batches, description, #editors, #find_config_from_path, #get_version, hl, inherited, #initialize, it, names, #parse_options, summary

Instance Method Details

#command_optionsObject



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/pik/commands/gemsync_command.rb', line 49

def command_options
  super
  sep =<<SEP
  Examples:

C:\\>ruby -v
ruby 1.8.6 (2009-03-31 patchlevel 368) [i386-mingw32]

C:\\>pik gemsync 191 p2
Gem ZenTest-4.1.4.gem already installed
Installing xml-simple-1.0.12.gem
Successfully installed xml-simple-1.0.12
1 gem installed
...
SEP
  options.separator sep
end

#executeObject



8
9
10
11
12
# File 'lib/pik/commands/gemsync_command.rb', line 8

def execute
  target  = self.class.choose_from(@args, config)
  current = get_version
  install_gems(current, target) if target
end

#gem_cache(version) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
# File 'lib/pik/commands/gemsync_command.rb', line 32

def gem_cache(version)
  conf = config[version]
  path = if conf[:gem_home] 
    Pathname.new( conf[:gem_home] )
  else
    cmd = ruby_exe(conf[:path]).to_s + " -rubygems -e \"puts Gem.default_path.last\""
    Pathname.new( `#{cmd}`.chomp ) 
  end
  puts path + "cache"
  path + "cache"
end

#gem_install(file) ⇒ Object



44
45
46
47
# File 'lib/pik/commands/gemsync_command.rb', line 44

def gem_install(file)
  @batch.echo "Installing #{file.basename}"
  @batch.call "gem install -q --no-rdoc --no-ri #{file}"
end

#install_gems(current, target) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/pik/commands/gemsync_command.rb', line 14

def install_gems(current, target)
  switch_path_to(config[target])
  switch_gem_home_to(config[target][:gem_home]) 
  target_cache = gem_cache(target)
  
  gem_cache(current).find do |file|
    if file.file?
      if (target_cache + file.basename).exist? 
        @batch.echo "Gem #{file.basename} already installed"
      else
        gem_install(file)
      end
    end
  end
  switch_path_to(config[current])
  switch_gem_home_to(config[target][:gem_home]) 
end