Class: Bundler::SpecSet
- Inherits:
-
Object
- Object
- Bundler::SpecSet
- Includes:
- Enumerable, Gem::TSort
- Defined in:
- lib/bundler/spec_set.rb
Instance Method Summary collapse
- #-(other) ⇒ Object
- #<<(spec) ⇒ Object
- #[](key) ⇒ Object
- #[]=(key, value) ⇒ Object
- #add_extra_platforms!(platforms) ⇒ Object
- #add_originally_invalid_platforms!(platforms, originally_invalid_platforms) ⇒ Object
- #delete(specs) ⇒ Object
- #delete_by_name(name) ⇒ Object
- #each(&b) ⇒ Object
- #empty? ⇒ Boolean
- #find_by_name_and_platform(name, platform) ⇒ Object
- #for(dependencies, platforms = [nil], legacy_platforms = [nil], skips: []) ⇒ Object
- #incomplete_for_platform?(deps, platform) ⇒ Boolean
- #incomplete_specs ⇒ Object
- #incomplete_specs_for_platform(deps, platform) ⇒ Object
-
#initialize(specs) ⇒ SpecSet
constructor
A new instance of SpecSet.
- #insecurely_materialized_specs ⇒ Object
- #length ⇒ Object
- #materialize(deps) ⇒ Object
-
#materialized_for_all_platforms ⇒ Array<Gem::Specification>
Materialize for all the specs in the spec set, regardless of what platform they're for.
- #missing_specs ⇒ Object
- #missing_specs_for(deps) ⇒ Object
- #names ⇒ Object
- #normalize_platforms!(deps, platforms) ⇒ Object
- #partially_missing_specs ⇒ Object
- #remove_invalid_platforms!(deps, platforms, skips: []) ⇒ Object
- #size ⇒ Object
- #sort! ⇒ Object
- #specs_with_additional_variants_from(other) ⇒ Object
- #to_a ⇒ Object
- #to_hash ⇒ Object
- #to_s ⇒ Object
- #valid?(s) ⇒ Boolean
- #validate_deps(s) ⇒ Object
- #version_for(name) ⇒ Object
- #what_required(spec) ⇒ Object
Constructor Details
#initialize(specs) ⇒ SpecSet
Returns a new instance of SpecSet.
10 11 12 |
# File 'lib/bundler/spec_set.rb', line 10 def initialize(specs) @specs = specs end |
Instance Method Details
#-(other) ⇒ Object
176 177 178 |
# File 'lib/bundler/spec_set.rb', line 176 def -(other) SharedHelpers.feature_removed! "SpecSet#- has been removed with no replacement" end |
#<<(spec) ⇒ Object
207 208 209 |
# File 'lib/bundler/spec_set.rb', line 207 def <<(spec) SharedHelpers.feature_removed! "SpecSet#<< has been removed with no replacement" end |
#[](key) ⇒ Object
98 99 100 101 |
# File 'lib/bundler/spec_set.rb', line 98 def [](key) key = key.name if key.respond_to?(:name) lookup[key]&.reverse || [] end |
#[]=(key, value) ⇒ Object
103 104 105 106 107 |
# File 'lib/bundler/spec_set.rb', line 103 def []=(key, value) delete_by_name(key) add_spec(value) end |
#add_extra_platforms!(platforms) ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/bundler/spec_set.rb', line 66 def add_extra_platforms!(platforms) if @specs.empty? platforms.concat([Gem::Platform::RUBY]).uniq return end new_platforms = all_platforms.select do |platform| next if platforms.include?(platform) next unless Gem::Platform.generic(platform) == Gem::Platform::RUBY complete_platform(platform) end return if new_platforms.empty? platforms.concat(new_platforms) return if new_platforms.include?(Bundler.local_platform) less_specific_platform = new_platforms.find {|platform| platform != Gem::Platform::RUBY && Bundler.local_platform === platform && platform === Bundler.local_platform } platforms.delete(Bundler.local_platform) if less_specific_platform end |
#add_originally_invalid_platforms!(platforms, originally_invalid_platforms) ⇒ Object
46 47 48 49 50 |
# File 'lib/bundler/spec_set.rb', line 46 def add_originally_invalid_platforms!(platforms, originally_invalid_platforms) originally_invalid_platforms.each do |originally_invalid_platform| platforms << originally_invalid_platform if complete_platform(originally_invalid_platform) end end |
#delete(specs) ⇒ Object
109 110 111 |
# File 'lib/bundler/spec_set.rb', line 109 def delete(specs) Array(specs).each {|spec| remove_spec(spec) } end |
#delete_by_name(name) ⇒ Object
188 189 190 191 192 193 194 |
# File 'lib/bundler/spec_set.rb', line 188 def delete_by_name(name) @specs.reject! {|spec| spec.name == name } @sorted&.reject! {|spec| spec.name == name } return if @lookup.nil? @lookup[name] = nil end |
#each(&b) ⇒ Object
223 224 225 |
# File 'lib/bundler/spec_set.rb', line 223 def each(&b) sorted.each(&b) end |
#empty? ⇒ Boolean
219 220 221 |
# File 'lib/bundler/spec_set.rb', line 219 def empty? @specs.empty? end |
#find_by_name_and_platform(name, platform) ⇒ Object
180 181 182 |
# File 'lib/bundler/spec_set.rb', line 180 def find_by_name_and_platform(name, platform) @specs.detect {|spec| spec.name == name && spec.installable_on_platform?(platform) } end |
#for(dependencies, platforms = [nil], legacy_platforms = [nil], skips: []) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/bundler/spec_set.rb', line 14 def for(dependencies, platforms = [nil], legacy_platforms = [nil], skips: []) if [true, false].include?(platforms) Bundler::SharedHelpers.feature_removed! \ "SpecSet#for received a `check` parameter, but that's no longer used and deprecated. " \ "SpecSet#for always implicitly performs validation. Please remove this parameter" end materialize_dependencies(dependencies, platforms, skips: skips) @materializations.flat_map(&:specs).uniq end |
#incomplete_for_platform?(deps, platform) ⇒ Boolean
142 143 144 |
# File 'lib/bundler/spec_set.rb', line 142 def incomplete_for_platform?(deps, platform) incomplete_specs_for_platform(deps, platform).any? end |
#incomplete_specs ⇒ Object
168 169 170 |
# File 'lib/bundler/spec_set.rb', line 168 def incomplete_specs @materializations.flat_map(&:incomplete_specs) end |
#incomplete_specs_for_platform(deps, platform) ⇒ Object
146 147 148 149 150 151 152 |
# File 'lib/bundler/spec_set.rb', line 146 def incomplete_specs_for_platform(deps, platform) return [] if @specs.empty? validation_set = self.class.new(@specs) validation_set.for(deps, [platform]) validation_set.incomplete_specs end |
#insecurely_materialized_specs ⇒ Object
172 173 174 |
# File 'lib/bundler/spec_set.rb', line 172 def insecurely_materialized_specs materialized_specs.select(&:insecurely_materialized?) end |
#length ⇒ Object
211 212 213 |
# File 'lib/bundler/spec_set.rb', line 211 def length @specs.length end |
#materialize(deps) ⇒ Object
125 126 127 128 129 |
# File 'lib/bundler/spec_set.rb', line 125 def materialize(deps) materialize_dependencies(deps) SpecSet.new(materialized_specs) end |
#materialized_for_all_platforms ⇒ Array<Gem::Specification>
Materialize for all the specs in the spec set, regardless of what platform they're for
133 134 135 136 137 138 139 140 |
# File 'lib/bundler/spec_set.rb', line 133 def materialized_for_all_platforms @specs.map do |s| next s unless s.is_a?(LazySpecification) spec = s.materialize_for_cache raise GemNotFound, "Could not find #{s.full_name} in any of the sources" unless spec spec end end |
#missing_specs ⇒ Object
160 161 162 |
# File 'lib/bundler/spec_set.rb', line 160 def missing_specs @materializations.flat_map(&:completely_missing_specs) end |
#missing_specs_for(deps) ⇒ Object
154 155 156 157 158 |
# File 'lib/bundler/spec_set.rb', line 154 def missing_specs_for(deps) materialize_dependencies(deps) missing_specs end |
#names ⇒ Object
227 228 229 |
# File 'lib/bundler/spec_set.rb', line 227 def names lookup.keys end |
#normalize_platforms!(deps, platforms) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/bundler/spec_set.rb', line 26 def normalize_platforms!(deps, platforms) remove_invalid_platforms!(deps, platforms) add_extra_platforms!(platforms) platforms.map! do |platform| next platform if platform == Gem::Platform::RUBY begin Integer(platform.version) rescue ArgumentError, TypeError next platform end less_specific_platform = Gem::Platform.new([platform.cpu, platform.os, nil]) next platform if incomplete_for_platform?(deps, less_specific_platform) less_specific_platform end.uniq! end |
#partially_missing_specs ⇒ Object
164 165 166 |
# File 'lib/bundler/spec_set.rb', line 164 def partially_missing_specs @materializations.flat_map(&:partially_missing_specs) end |
#remove_invalid_platforms!(deps, platforms, skips: []) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/bundler/spec_set.rb', line 52 def remove_invalid_platforms!(deps, platforms, skips: []) invalid_platforms = [] platforms.reject! do |platform| next false if skips.include?(platform) invalid = incomplete_for_platform?(deps, platform) invalid_platforms << platform if invalid invalid end invalid_platforms end |
#size ⇒ Object
215 216 217 |
# File 'lib/bundler/spec_set.rb', line 215 def size @specs.size end |
#sort! ⇒ Object
113 114 115 |
# File 'lib/bundler/spec_set.rb', line 113 def sort! self end |
#specs_with_additional_variants_from(other) ⇒ Object
184 185 186 |
# File 'lib/bundler/spec_set.rb', line 184 def specs_with_additional_variants_from(other) sorted | additional_variants_from(other) end |
#to_a ⇒ Object
117 118 119 |
# File 'lib/bundler/spec_set.rb', line 117 def to_a sorted.dup end |
#to_hash ⇒ Object
121 122 123 |
# File 'lib/bundler/spec_set.rb', line 121 def to_hash lookup.dup end |
#to_s ⇒ Object
235 236 237 |
# File 'lib/bundler/spec_set.rb', line 235 def to_s map(&:full_name).to_s end |
#valid?(s) ⇒ Boolean
231 232 233 |
# File 'lib/bundler/spec_set.rb', line 231 def valid?(s) s. && valid_dependencies?(s) end |
#validate_deps(s) ⇒ Object
87 88 89 90 91 92 93 94 95 96 |
# File 'lib/bundler/spec_set.rb', line 87 def validate_deps(s) s.runtime_dependencies.each do |dep| next if dep.name == "bundler" return :missing unless names.include?(dep.name) return :invalid if none? {|spec| dep.matches_spec?(spec) } end :valid end |
#version_for(name) ⇒ Object
196 197 198 |
# File 'lib/bundler/spec_set.rb', line 196 def version_for(name) exemplary_spec(name)&.version end |
#what_required(spec) ⇒ Object
200 201 202 203 204 205 |
# File 'lib/bundler/spec_set.rb', line 200 def what_required(spec) unless req = find {|s| s.runtime_dependencies.any? {|d| d.name == spec.name } } return [spec] end what_required(req) << spec end |