Class: Jets::Gems::Extract::Base
- Inherits:
-
Object
- Object
- Jets::Gems::Extract::Base
- Defined in:
- lib/jets/gems/extract/base.rb
Defined Under Namespace
Classes: NotFound
Constant Summary collapse
- @@log_level =
default level is :info
:info
Instance Attribute Summary collapse
-
#source_url ⇒ Object
readonly
Returns the value of attribute source_url.
Instance Method Summary collapse
- #clean_downloads(folder) ⇒ Object
-
#download_file(source_url, dest) ⇒ Object
Returns the dest path.
-
#initialize(name, options = {}) ⇒ Base
constructor
A new instance of Base.
-
#log_level=(val) ⇒ Object
@@log_level = :debug # uncomment to debug.
- #project_root ⇒ Object
- #say(message, level = :info) ⇒ Object
- #sh(command) ⇒ Object
- #unzip(zipfile_path, parent_folder_dest) ⇒ Object
- #url_exists?(url) ⇒ Boolean
Constructor Details
#initialize(name, options = {}) ⇒ Base
Returns a new instance of Base.
8 9 10 11 12 13 14 |
# File 'lib/jets/gems/extract/base.rb', line 8 def initialize(name, ={}) @name = name @options = @downloads_root = [:downloads_root] || "/tmp/jets/#{Jets.config.project_name}/lambdagems" @source_url = [:source_url] || Jets.default_gems_source end |
Instance Attribute Details
#source_url ⇒ Object (readonly)
Returns the value of attribute source_url.
7 8 9 |
# File 'lib/jets/gems/extract/base.rb', line 7 def source_url @source_url end |
Instance Method Details
#clean_downloads(folder) ⇒ Object
16 17 18 19 20 |
# File 'lib/jets/gems/extract/base.rb', line 16 def clean_downloads(folder) path = "#{@downloads_root}/downloads/#{folder}" say "Removing cache: #{path}" FileUtils.rm_rf(path) end |
#download_file(source_url, dest) ⇒ Object
Returns the dest path
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/jets/gems/extract/base.rb', line 39 def download_file(source_url, dest) say "Url #{source_url}" return unless url_exists?(source_url) if File.exist?(dest) say "File already downloaded #{dest}" return dest end say "Downloading..." FileUtils.mkdir_p(File.dirname(dest)) # ensure parent folder exists File.open(dest, 'wb') do |saved_file| open(source_url, 'rb') do |read_file| saved_file.write(read_file.read) end end dest end |
#log_level=(val) ⇒ Object
@@log_level = :debug # uncomment to debug
65 66 67 |
# File 'lib/jets/gems/extract/base.rb', line 65 def log_level=(val) @@log_level = val end |
#project_root ⇒ Object
59 60 61 |
# File 'lib/jets/gems/extract/base.rb', line 59 def project_root @options[:project_root] || "." end |
#say(message, level = :info) ⇒ Object
69 70 71 72 |
# File 'lib/jets/gems/extract/base.rb', line 69 def say(, level=:info) enabled = @@log_level == :debug || level == :debug puts() if enabled end |
#sh(command) ⇒ Object
26 27 28 29 30 31 |
# File 'lib/jets/gems/extract/base.rb', line 26 def sh(command) say "=> #{command}".color(:green) success = system(command) abort("Command Failed") unless success success end |
#unzip(zipfile_path, parent_folder_dest) ⇒ Object
22 23 24 |
# File 'lib/jets/gems/extract/base.rb', line 22 def unzip(zipfile_path, parent_folder_dest) sh("cd #{parent_folder_dest} && unzip -qo #{zipfile_path}") end |