Top Level Namespace
Defined Under Namespace
Modules: Erhu
Classes: Cmd, Object
Instance Method Summary
collapse
Instance Method Details
#error!(*args) ⇒ Object
33
34
35
36
|
# File 'lib/erhu/init.rb', line 33
def error!(*args)
error = pastel.red.bold.detach
puts "Error: #{error.(*args)}"
end
|
114
115
116
117
118
119
120
121
122
123
|
# File 'lib/erhu/init.rb', line 114
def (url)
uri = URI.parse(url)
path = uri.path
if path.end_with?('.tar.gz')
'.tar.gz'
else
File.extname(path)
end
end
|
89
90
91
|
# File 'lib/erhu/init.rb', line 89
def http
http = Down::Http.new
end
|
29
30
31
|
# File 'lib/erhu/init.rb', line 29
def pastel
$pastel ||= Pastel.new
end
|
25
26
27
|
# File 'lib/erhu/init.rb', line 25
def platform
$platform ||= TTY::Platform.new
end
|
#ungzip(tar_gz_archive, destination) ⇒ Object
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
# File 'lib/erhu/init.rb', line 58
def ungzip(tar_gz_archive, destination)
spinner = TTY::Spinner.new("[:spinner] extracted :title ...")
spinner.auto_spin
Gem::Package::TarReader.new( Zlib::GzipReader.open tar_gz_archive) do |tar|
dest = nil
tar.each do |entry|
spinner.update title: entry.full_name
if entry.full_name == '././@LongLink'
dest = File.join destination, entry.read.strip
next
end
dest ||= File.join destination, entry.full_name.split('/')[1..-1].join('/')
if entry.directory?
FileUtils.rm_rf dest unless File.directory? dest
FileUtils.mkdir_p dest, :mode => entry..mode, :verbose => false
elsif entry.file?
FileUtils.rm_rf dest unless File.file? dest
File.open dest, "wb" do |f|
f.print entry.read
end
FileUtils.chmod entry..mode, dest, :verbose => false
elsif entry..typeflag == '2' File.symlink entry..linkname, dest
end
dest = nil
end
end
spinner.update title: "ALL"
spinner.stop("Done!")
end
|
#unzip(zip_file_path, target_directory) ⇒ Object
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
# File 'lib/erhu/init.rb', line 43
def unzip(zip_file_path, target_directory)
spinner = TTY::Spinner.new("[:spinner] extracted :title ...")
spinner.auto_spin
Zip::File.open(zip_file_path) do |zip_file|
zip_file.each do |entry|
dest_path = File.join(target_directory, entry.name.split('/')[1..-1].join('/'))
entry.(dest_path)
spinner.update title: entry.name
end
end
spinner.update title: "ALL"
spinner.stop("Done!")
end
|
#warn!(*args) ⇒ Object
38
39
40
41
|
# File 'lib/erhu/init.rb', line 38
def warn!(*args)
warning = pastel.yellow.detach
puts "Warning: #{warning.(*args)}"
end
|