Class: Jets::Gems::Extract::Gem
- Defined in:
- lib/jets/gems/extract/gem.rb
Constant Summary collapse
- VERSION_PATTERN =
/-(\d+\.\d+.*)/
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
-
#download_gem ⇒ Object
Downloads and extracts the linux gem into the proper directory.
- #download_path(filename) ⇒ Object
-
#full_gem_name ⇒ Object
ensure that we always have the full gem name.
- #gem_name ⇒ Object
-
#gem_url ⇒ Object
full_gem_name: byebug-9.1.0.
-
#remove_current_gem ⇒ Object
Finds any currently install gems that matched with the gem name and version and remove them first.
- #ruby_folder ⇒ Object
- #run ⇒ Object
- #unzip_file(zipfile_path) ⇒ Object
Methods inherited from Base
#clean_downloads, #download_file, #initialize, #log_level=, #project_root, #say, #sh, #unzip, #url_exists?
Constructor Details
This class inherits a constructor from Jets::Gems::Extract::Base
Instance Method Details
#download_gem ⇒ Object
Downloads and extracts the linux gem into the proper directory. Extracts to: . (current directory)
It produces a ‘bundled` folder. The folder contains the re-produced directory structure. Example with the gem: byebug-9.1.0
vendor/gems/ruby/2.5.0/extensions/x86_64-darwin-16/2.5.0-static/byebug-9.1.0
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/jets/gems/extract/gem.rb', line 57 def download_gem # download - also move to /tmp/jets/demo/compiled_gems folder url = gem_url tarball_dest = download_file(url, download_path(File.basename(url))) unless tarball_dest = "Url: #{url} not found" if @options[:exit_on_error] say exit else raise NotFound.new() end end say "Downloaded to: #{tarball_dest}" tarball_dest end |
#download_path(filename) ⇒ Object
74 75 76 |
# File 'lib/jets/gems/extract/gem.rb', line 74 def download_path(filename) "#{@downloads_root}/downloads/gems/#{filename}" end |
#full_gem_name ⇒ Object
ensure that we always have the full gem name
31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/jets/gems/extract/gem.rb', line 31 def full_gem_name return @full_gem_name if @full_gem_name if @name.match(VERSION_PATTERN) @full_gem_name = @name return @full_gem_name end # name doesnt have a version yet, so grab the latest version and add it version = Gems.versions(@name).first @full_gem_name = "#{@name}-#{version["number"]}" end |
#gem_name ⇒ Object
44 45 46 |
# File 'lib/jets/gems/extract/gem.rb', line 44 def gem_name full_gem_name.gsub(VERSION_PATTERN,'') # folder: byebug end |
#gem_url ⇒ Object
full_gem_name: byebug-9.1.0
97 98 99 |
# File 'lib/jets/gems/extract/gem.rb', line 97 def gem_url "#{source_url}/gems/#{ruby_folder}/#{gem_name}/#{full_gem_name}.zip" end |
#remove_current_gem ⇒ Object
Finds any currently install gems that matched with the gem name and version and remove them first. We clean up the current install gems first in case it was previously installed and has different *.so files that can be accidentally required. This happened with the pg gem.
83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/jets/gems/extract/gem.rb', line 83 def remove_current_gem say "Removing current #{full_gem_name} gem installation:" gem_dirs = Dir.glob("#{project_root}/**/*").select do |path| File.directory?(path) && path =~ %r{vendor/gems} && File.basename(path) == full_gem_name end gem_dirs.each do |dir| say " rm -rf #{dir}" FileUtils.rm_rf(dir) end end |
#ruby_folder ⇒ Object
101 102 103 |
# File 'lib/jets/gems/extract/gem.rb', line 101 def ruby_folder Jets::Gems.ruby_folder end |
#run ⇒ Object
14 15 16 17 18 19 20 21 |
# File 'lib/jets/gems/extract/gem.rb', line 14 def run say "Looking for #{full_gem_name} gem in: #{@options[:source_url]}" clean_downloads(:gems) if @options[:clean] zipfile_path = download_gem remove_current_gem unzip_file(zipfile_path) say("Gem #{full_gem_name} unpacked at #{project_root}") end |
#unzip_file(zipfile_path) ⇒ Object
23 24 25 26 27 28 |
# File 'lib/jets/gems/extract/gem.rb', line 23 def unzip_file(zipfile_path) dest = "#{Jets.build_root}/stage/opt" say "Unpacking into #{dest}" FileUtils.mkdir_p(dest) unzip(zipfile_path, dest) end |