Class: Prebundler::GemRef
- Inherits:
-
Object
- Object
- Prebundler::GemRef
- Defined in:
- lib/prebundler/gem_ref.rb
Direct Known Subclasses
Constant Summary collapse
- REF_TYPES =
[PathGemRef, GitGemRef]
- DEFAULT_SOURCE =
'https://rubygems.org'
Instance Attribute Summary collapse
-
#bundle_path ⇒ Object
readonly
Returns the value of attribute bundle_path.
-
#dependencies ⇒ Object
Returns the value of attribute dependencies.
-
#groups ⇒ Object
readonly
Returns the value of attribute groups.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#prefix ⇒ Object
Returns the value of attribute prefix.
-
#spec ⇒ Object
Returns the value of attribute spec.
Class Method Summary collapse
Instance Method Summary collapse
- #add_to_tar(tar_file) ⇒ Object
- #executables ⇒ Object
- #extension_dir ⇒ Object
- #gemspecs ⇒ Object
- #id ⇒ Object
-
#initialize(name, bundle_path, options = {}) ⇒ GemRef
constructor
A new instance of GemRef.
- #install ⇒ Object
- #install_dir ⇒ Object
- #install_from_tar(tar_file) ⇒ Object
- #install_path ⇒ Object
- #installable? ⇒ Boolean
- #relative_extension_dir ⇒ Object
- #relative_gem_dir ⇒ Object
- #relative_gemspec_files ⇒ Object
- #source ⇒ Object (also: #remote)
- #spec_path ⇒ Object
- #storable? ⇒ Boolean
- #tar_file ⇒ Object
- #to_gem ⇒ Object
- #version ⇒ Object
Constructor Details
#initialize(name, bundle_path, options = {}) ⇒ GemRef
Returns a new instance of GemRef.
19 20 21 22 23 24 25 26 |
# File 'lib/prebundler/gem_ref.rb', line 19 def initialize(name, bundle_path, = {}) @name = name @bundle_path = bundle_path @groups = Set.new([:groups]) @source = [:source] @dependencies = [:dependencies] @prefix = [:prefix] end |
Instance Attribute Details
#bundle_path ⇒ Object (readonly)
Returns the value of attribute bundle_path.
16 17 18 |
# File 'lib/prebundler/gem_ref.rb', line 16 def bundle_path @bundle_path end |
#dependencies ⇒ Object
Returns the value of attribute dependencies.
17 18 19 |
# File 'lib/prebundler/gem_ref.rb', line 17 def dependencies @dependencies end |
#groups ⇒ Object (readonly)
Returns the value of attribute groups.
16 17 18 |
# File 'lib/prebundler/gem_ref.rb', line 16 def groups @groups end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
16 17 18 |
# File 'lib/prebundler/gem_ref.rb', line 16 def name @name end |
#prefix ⇒ Object
Returns the value of attribute prefix.
17 18 19 |
# File 'lib/prebundler/gem_ref.rb', line 17 def prefix @prefix end |
#spec ⇒ Object
Returns the value of attribute spec.
17 18 19 |
# File 'lib/prebundler/gem_ref.rb', line 17 def spec @spec end |
Class Method Details
.create(name, bundle_path, options = {}) ⇒ Object
10 11 12 13 |
# File 'lib/prebundler/gem_ref.rb', line 10 def create(name, bundle_path, = {}) ref_type = REF_TYPES.find { |rt| rt.accepts?() } || self ref_type.new(name, bundle_path, ) end |
Instance Method Details
#add_to_tar(tar_file) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/prebundler/gem_ref.rb', line 63 def add_to_tar(tar_file) tar_flags = File.exist?(tar_file) ? '-rf' : '-cf' system "tar -C #{bundle_path} #{tar_flags} #{tar_file} #{relative_gem_dir}" relative_gemspec_files.each do |relative_gemspec_file| system "tar -C #{bundle_path} -rf #{tar_file} #{relative_gemspec_file}" end if File.directory?(extension_dir) system "tar -C #{bundle_path} -rf #{tar_file} #{relative_extension_dir}" end gemspecs.each do |gemspec| gemspec.executables.each do |executable| system "tar -C #{bundle_path} -rf #{tar_file} #{File.join(relative_gem_dir, gemspec.bindir, executable)}" end end end |
#executables ⇒ Object
83 84 85 |
# File 'lib/prebundler/gem_ref.rb', line 83 def executables gemspecs.flat_map(&:executables) end |
#extension_dir ⇒ Object
119 120 121 |
# File 'lib/prebundler/gem_ref.rb', line 119 def extension_dir File.join(bundle_path, relative_extension_dir) end |
#gemspecs ⇒ Object
87 88 89 90 91 |
# File 'lib/prebundler/gem_ref.rb', line 87 def gemspecs @gemspecs ||= relative_gemspec_files.map do |relative_gemspec_file| Bundler.load_gemspec(File.join(bundle_path, relative_gemspec_file)) end end |
#id ⇒ Object
42 43 44 |
# File 'lib/prebundler/gem_ref.rb', line 42 def id "#{name}-#{version}" end |
#install ⇒ Object
50 51 52 53 54 55 56 |
# File 'lib/prebundler/gem_ref.rb', line 50 def install Bundler.with_unbundled_env do system({ "GEM_HOME" => bundle_path }, "gem install -N --ignore-dependencies --source #{source} #{name} -v #{version}") end $?.exitstatus end |
#install_dir ⇒ Object
109 110 111 112 113 114 115 116 117 |
# File 'lib/prebundler/gem_ref.rb', line 109 def install_dir @install_dir ||= begin base = File.join(install_path, id) find_platform_dir(base) do |dir| File.directory?(dir) end end end |
#install_from_tar(tar_file) ⇒ Object
58 59 60 61 |
# File 'lib/prebundler/gem_ref.rb', line 58 def install_from_tar(tar_file) system "tar -C #{bundle_path} -xf #{tar_file}" $?.exitstatus == 0 end |
#install_path ⇒ Object
101 102 103 |
# File 'lib/prebundler/gem_ref.rb', line 101 def install_path File.join(bundle_path, 'gems') end |
#installable? ⇒ Boolean
93 94 95 |
# File 'lib/prebundler/gem_ref.rb', line 93 def installable? true end |
#relative_extension_dir ⇒ Object
123 124 125 |
# File 'lib/prebundler/gem_ref.rb', line 123 def relative_extension_dir File.join('extensions', Bundler.local_platform.to_s, Gem.extension_api_version.to_s, id) end |
#relative_gem_dir ⇒ Object
127 128 129 130 131 132 133 134 135 |
# File 'lib/prebundler/gem_ref.rb', line 127 def relative_gem_dir @relative_gem_dir ||= begin base = File.join('gems', id) find_platform_dir(base) do |dir| File.directory?(File.join(bundle_path, dir)) end end end |
#relative_gemspec_files ⇒ Object
137 138 139 140 141 |
# File 'lib/prebundler/gem_ref.rb', line 137 def relative_gemspec_files Dir.chdir(bundle_path) do Dir.glob(File.join('specifications', "#{id}*.gemspec")) end end |
#source ⇒ Object Also known as: remote
36 37 38 |
# File 'lib/prebundler/gem_ref.rb', line 36 def source @source ||= DEFAULT_SOURCE end |
#spec_path ⇒ Object
105 106 107 |
# File 'lib/prebundler/gem_ref.rb', line 105 def spec_path File.join(bundle_path, 'specifications') end |
#storable? ⇒ Boolean
97 98 99 |
# File 'lib/prebundler/gem_ref.rb', line 97 def storable? true end |
#tar_file ⇒ Object
143 144 145 146 |
# File 'lib/prebundler/gem_ref.rb', line 143 def tar_file file = File.join(Bundler.local_platform.to_s, Prebundler.platform_version, Gem.extension_api_version.to_s, "#{id}.tar") prefix && !prefix.empty? ? File.join(prefix, file) : file end |
#to_gem ⇒ Object
28 29 30 |
# File 'lib/prebundler/gem_ref.rb', line 28 def to_gem "gem '#{name}', '= #{version}'" end |
#version ⇒ Object
46 47 48 |
# File 'lib/prebundler/gem_ref.rb', line 46 def version spec.version.to_s end |