-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
extract.rb
44 lines (37 loc) · 1.21 KB
/
extract.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
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
require "base64"
require "tempfile"
require "zip"
def extract_gradle(target)
extract_zip(Radon::Environments.getTargetOf('gradle'), target)
end
def extract_java(target)
extract_zip(Radon::Environments.getTargetOf('java'), target)
end
def extract_maven(target)
extract_zip(Radon::Environments.getTargetOf('maven'), target)
end
def extract_python(target)
extract_zip(Radon::Environments.getTargetOf('python'), target)
end
def extract_ruby(target)
extract_zip(Radon::Environments.getTargetOf('ruby (beta)'), target)
find_and_replace_all(target, '{{NAME}}', projectify(target).split('-').collect(&:capitalize).join)
end
# Extracts some zip data to the passed destination
def extract_zip(file, destination)
puts "Creating project under #{File.expand_path(destination)}" unless $quiet
create(destination)
FileUtils.mkdir_p(destination)
Zip::File.open(file) do |zip_file|
zip_file.each do |f|
fname = f.name.gsub('{{NAME}}', projectify(destination))
fpath = File.join(destination, fname)
if File.exists?(fpath)
skip(fpath)
else
create(fpath)
end
zip_file.extract(f, fpath) unless File.exist?(fpath)
end
end
end