Class: Lhj::Command::Init
- Inherits:
-
Lhj::Command
- Object
- CLAide::Command
- Lhj::Command
- Lhj::Command::Init
- Defined in:
- lib/lhj/command/init.rb
Overview
sync config
Instance Method Summary collapse
- #down_load_urls ⇒ Object
- #download_file ⇒ Object
- #file_name_with_url(url) ⇒ Object
- #run ⇒ Object
- #save_file(url, target) ⇒ Object
- #target_folder ⇒ Object
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 |
#run ⇒ Object
14 15 16 17 |
# File 'lib/lhj/command/init.rb', line 14 def run 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 |