Class: Pik::GemSync
Instance Attribute Summary collapse
Attributes inherited from Command
#config, #debug, #options, #output, #version
Instance Method Summary
collapse
Methods inherited from Command
#actual_gem_home, #add_sigint_handler, aka, choose_from, #close, cmd_name, #cmd_name, #create, #current_gem_bin_path, #current_version?, #default_gem_home, #delete_old_pik_script, description, #editors, #find_config_from_path, #gem_path, #get_version, hl, inherited, #initialize, it, names, #parse_options, #pik_version, #sh, summary
Constructor Details
This class inherits a constructor from Pik::Command
Instance Attribute Details
Returns the value of attribute quiet.
8
9
10
|
# File 'lib/pik/commands/gemsync_command.rb', line 8
def quiet
@quiet
end
|
Returns the value of attribute remote.
8
9
10
|
# File 'lib/pik/commands/gemsync_command.rb', line 8
def remote
@remote
end
|
Instance Method Details
#command_options ⇒ Object
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
|
# File 'lib/pik/commands/gemsync_command.rb', line 80
def command_options
super
sep =<<SEP
Gemsync syncs the current version of ruby with the one given.
This tool is fairly dumb. Syncing across implementations is
probably a bad idea.
Examples:
syncs ruby 1.8.6 with the gems install for 1.9.1
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
options.on("--quiet", "-q", "Sync without prompting, fails if platforms don't match") do |value|
@quiet = value
end
options.on("--remote", "-r", "Pull gems from a remote repository") do |value|
@remote = value
end
end
|
10
11
12
13
14
15
16
17
18
19
20
21
|
# File 'lib/pik/commands/gemsync_command.rb', line 10
def execute
source = self.class.choose_from(@args, config)
raise "Couldn't find a version from the pattern given: '#{@args.join(' ')}'" unless source
current = find_config_from_path
if platform_consistent?(source, current)
puts "** Syncing: #{current}\n with: #{source}"
puts " from a remote repository." if remote
puts
install_gems(current, source)
end
end
|
#gem_cache(version) ⇒ Object
70
71
72
73
74
75
76
77
78
|
# File 'lib/pik/commands/gemsync_command.rb', line 70
def gem_cache(version)
conf = config[version]
cmd = Which::Ruby.exe(conf[:path]).to_s + " -rubygems -e \"puts Gem.default_path.last\""
path = conf[:gem_home] ? Pathname( conf[:gem_home] ) : Pathname( `#{cmd}`.chomp )
cache = path + "cache"
puts "cache: #{cache}" if debug
cache
end
|
#gem_file(file) ⇒ Object
59
60
61
62
63
64
65
66
67
68
|
# File 'lib/pik/commands/gemsync_command.rb', line 59
def gem_file(file)
if remote
gem_re = /(.+)\-(\d+\.\d+\.\d+).+/
file, gem_name, version = file.basename.to_s.match(gem_re).to_a
"#{gem_name} --version \"=#{version}\" --remote"
else
file.sub(/.*\s.*/m, '"\&"')
end
end
|
#install_gems(current, source) ⇒ Object
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
# File 'lib/pik/commands/gemsync_command.rb', line 41
def install_gems(current, source)
target_cache = gem_cache(current)
gem_cache(source).find do |file|
if file.file?
if (target_cache + file.basename).exist?
puts "** Gem #{file.basename('.gem')} already installed"
else
puts "** Installing #{file.basename('.gem')}"
gem_opts = "install -q --no-rdoc --no-ri"
cmd = "#{Which::Gem.exe.basename} #{gem_opts} #{gem_file(file)}"
puts cmd if debug
system(cmd)
end
end
end
end
|
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
# File 'lib/pik/commands/gemsync_command.rb', line 23
def platform_consistent?(source, current)
s_platform = VersionParser.parse(source).platform
c_platform = VersionParser.parse(current).platform
return true if s_platform == c_platform || remote
msg =<<MSG
You appear to be attempting a gemsync from a different platform.
Sync: #{current}
with: #{source}
If you really want to sync, I recommend you quit and run gemsync with
the --remote flag.
MSG
raise msg if quiet
@hl.agree(msg + "Are you sure you'd like to continue?"){|answer| answer.default = 'no'}
end
|