Class: Jets::Gems::Extract::Base
- Inherits:
-
Object
- Object
- Jets::Gems::Extract::Base
- Defined in:
- lib/jets/gems/extract/base.rb
Direct Known Subclasses
Defined Under Namespace
Classes: NotFound
Constant Summary collapse
- @@log_level =
default level is :info
:info
Instance Attribute Summary collapse
-
#project_root ⇒ Object
readonly
Returns the value of attribute project_root.
Instance Method Summary collapse
- #clean_downloads(folder) ⇒ Object
-
#download_file(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.
- #say(message, level = :info) ⇒ Object
- #sh(command) ⇒ Object
-
#unzip(zipfile_path, parent_folder_dest) ⇒ Object
Using ‘ > /dev/null 2>&1` to suppress stderr message:.
Constructor Details
#initialize(name, options = {}) ⇒ Base
Returns a new instance of Base.
8 9 10 11 12 13 |
# File 'lib/jets/gems/extract/base.rb', line 8 def initialize(name, = {}) @name = name @options = ruby_folder = Jets::Gems.ruby_folder @downloads_root = [:downloads_root] || "/tmp/jets/#{Jets.config.project_name}/serverlessgems/#{ruby_folder}" end |
Instance Attribute Details
#project_root ⇒ Object (readonly)
Returns the value of attribute project_root.
7 8 9 |
# File 'lib/jets/gems/extract/base.rb', line 7 def project_root @project_root end |
Instance Method Details
#clean_downloads(folder) ⇒ Object
15 16 17 18 19 |
# File 'lib/jets/gems/extract/base.rb', line 15 def clean_downloads(folder) path = "#{@downloads_root}/downloads/#{folder}" say "Removing cache: #{path}" FileUtils.rm_rf(path) end |
#download_file(url, dest) ⇒ Object
Returns the dest path
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/jets/gems/extract/base.rb', line 37 def download_file(url, dest) if File.exist?(dest) && ENV["SG_FORCE_DOWNLOAD"].blank? say "File already downloaded #{dest}" return dest end say "Downloading..." downloaded = URI.open(url, "rb") { |read_file| read_file.read } FileUtils.mkdir_p(File.dirname(dest)) # ensure parent folder exists File.binwrite(dest, downloaded) dest end |
#log_level=(val) ⇒ Object
@@log_level = :debug # uncomment to debug
55 56 57 |
# File 'lib/jets/gems/extract/base.rb', line 55 def log_level=(val) @@log_level = val end |
#say(message, level = :info) ⇒ Object
59 60 61 62 |
# File 'lib/jets/gems/extract/base.rb', line 59 def say(, level = :info) enabled = @@log_level == :debug || level == :debug puts() if enabled end |
#sh(command) ⇒ Object
29 30 31 32 33 34 |
# File 'lib/jets/gems/extract/base.rb', line 29 def sh(command) say "=> #{command}".color(:green) success = system(command) abort("Command Failed #{command}") unless success success end |
#unzip(zipfile_path, parent_folder_dest) ⇒ Object
Using ‘ > /dev/null 2>&1` to suppress stderr message:
lchmod (file attributes) error: Function not implemented
25 26 27 |
# File 'lib/jets/gems/extract/base.rb', line 25 def unzip(zipfile_path, parent_folder_dest) sh("cd #{parent_folder_dest} && unzip -qo #{zipfile_path} > /dev/null 2>&1") end |