Class: Lhj::Command::Init
Overview
Instance Method Summary
collapse
#auto_spin, #initialize, #run, #stop
Constructor Details
This class inherits a constructor from Lhj::Command
Instance Method Details
#down_load_urls ⇒ Object
19
20
21
22
23
24
|
# File 'lib/lhj/command/init.rb', line 19
def down_load_urls
%w[http://aomi-ios-repo.oss-cn-shenzhen.aliyuncs.com/localizable_config.yml
http://aomi-ios-repo.oss-cn-shenzhen.aliyuncs.com/oss_config.yml
http://aomi-ios-repo.oss-cn-shenzhen.aliyuncs.com/yapi.yml
http://aomi-ios-repo.oss-cn-shenzhen.aliyuncs.com/zh2hant.yml]
end
|
#download_file ⇒ Object
42
43
44
45
46
47
48
49
|
# File 'lib/lhj/command/init.rb', line 42
def download_file
down_load_urls.each do |url|
file_name = file_name_with_url(url)
file_path = File.join(target_folder, file_name)
save_file(url, file_path) unless File.exist?(file_path)
end
puts "工具初始化完成 \n"
end
|
#file_name_with_url(url) ⇒ Object
38
39
40
|
# File 'lib/lhj/command/init.rb', line 38
def file_name_with_url(url)
url.scan(%r{/([^/]+)}).flatten.last
end
|
#handle ⇒ Object
14
15
16
17
|
# File 'lib/lhj/command/init.rb', line 14
def handle
FileUtils.mkdir_p(target_folder) unless File.exist?(target_folder)
download_file
end
|
#save_file(url, target) ⇒ Object
30
31
32
33
34
35
36
|
# File 'lib/lhj/command/init.rb', line 30
def save_file(url, target)
http_client = Faraday.new do |c|
c.adapter Faraday.default_adapter
end
response = http_client.get(url)
File.open(target, 'wb') { |fp| fp.write(response.body) }
end
|
#target_folder ⇒ Object
26
27
28
|
# File 'lib/lhj/command/init.rb', line 26
def target_folder
Lhj::Config.instance.home_dir
end
|