Module: Bundler::GemHelpers
- Included in:
- Definition, LockfileParser, MatchPlatform, Resolver
- Defined in:
- lib/bundler/gem_helpers.rb
Defined Under Namespace
Classes: PlatformMatch
Constant Summary collapse
- GENERIC_CACHE =
rubocop:disable Style/MutableConstant
{ Gem::Platform::RUBY => Gem::Platform::RUBY }
- GENERICS =
[ Gem::Platform::JAVA, *Gem::Platform::WINDOWS, ].freeze
Class Method Summary collapse
- .generic(p) ⇒ Object
- .generic_local_platform ⇒ Object
- .generic_local_platform_is_ruby? ⇒ Boolean
- .local_platform ⇒ Object
- .platform_specificity_match(spec_platform, user_platform) ⇒ Object
- .same_deps(spec, exemplary_spec) ⇒ Object
- .same_specificity(platform, spec, exemplary_spec) ⇒ Object
- .select_all_platform_match(specs, platform, force_ruby: false, prefer_locked: false) ⇒ Object
- .select_best_local_platform_match(specs, force_ruby: false) ⇒ Object
- .select_best_platform_match(specs, platform, force_ruby: false, prefer_locked: false) ⇒ Object
- .sort_and_filter_best_platform_match(matching, platform) ⇒ Object
- .sort_best_platform_match(matching, platform) ⇒ Object
Class Method Details
permalink .generic(p) ⇒ Object
[View source]
11 12 13 14 15 16 17 18 |
# File 'lib/bundler/gem_helpers.rb', line 11 def generic(p) GENERIC_CACHE[p] ||= begin found = GENERICS.find do |match| p === match end found || Gem::Platform::RUBY end end |
permalink .generic_local_platform ⇒ Object
[View source]
21 22 23 |
# File 'lib/bundler/gem_helpers.rb', line 21 def generic_local_platform generic(local_platform) end |
permalink .generic_local_platform_is_ruby? ⇒ Boolean
31 32 33 |
# File 'lib/bundler/gem_helpers.rb', line 31 def generic_local_platform_is_ruby? generic_local_platform == Gem::Platform::RUBY end |
permalink .local_platform ⇒ Object
[View source]
26 27 28 |
# File 'lib/bundler/gem_helpers.rb', line 26 def local_platform Bundler.local_platform end |
permalink .platform_specificity_match(spec_platform, user_platform) ⇒ Object
[View source]
36 37 38 39 40 |
# File 'lib/bundler/gem_helpers.rb', line 36 def platform_specificity_match(spec_platform, user_platform) spec_platform = Gem::Platform.new(spec_platform) PlatformMatch.specificity_score(spec_platform, user_platform) end |
permalink .same_deps(spec, exemplary_spec) ⇒ Object
[View source]
137 138 139 140 141 |
# File 'lib/bundler/gem_helpers.rb', line 137 def same_deps(spec, exemplary_spec) same_runtime_deps = spec.dependencies.sort == exemplary_spec.dependencies.sort = spec.required_ruby_version == exemplary_spec.required_ruby_version && spec.required_rubygems_version == exemplary_spec.required_rubygems_version same_runtime_deps && end |
permalink .same_specificity(platform, spec, exemplary_spec) ⇒ Object
[View source]
132 133 134 |
# File 'lib/bundler/gem_helpers.rb', line 132 def same_specificity(platform, spec, exemplary_spec) platform_specificity_match(spec.platform, platform) == platform_specificity_match(exemplary_spec.platform, platform) end |
permalink .select_all_platform_match(specs, platform, force_ruby: false, prefer_locked: false) ⇒ Object
[View source]
43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/bundler/gem_helpers.rb', line 43 def select_all_platform_match(specs, platform, force_ruby: false, prefer_locked: false) matching = if force_ruby specs.select {|spec| spec.match_platform(Gem::Platform::RUBY) && spec.force_ruby_platform! } else specs.select {|spec| spec.match_platform(platform) } end if prefer_locked locked_originally = matching.select {|spec| spec.is_a?(LazySpecification) } return locked_originally if locked_originally.any? end matching end |
permalink .select_best_local_platform_match(specs, force_ruby: false) ⇒ Object
[View source]
66 67 68 69 70 |
# File 'lib/bundler/gem_helpers.rb', line 66 def select_best_local_platform_match(specs, force_ruby: false) matching = select_all_platform_match(specs, local_platform, force_ruby: force_ruby).filter_map(&:materialized_for_installation) sort_best_platform_match(matching, local_platform) end |
permalink .select_best_platform_match(specs, platform, force_ruby: false, prefer_locked: false) ⇒ Object
[View source]
59 60 61 62 63 |
# File 'lib/bundler/gem_helpers.rb', line 59 def select_best_platform_match(specs, platform, force_ruby: false, prefer_locked: false) matching = select_all_platform_match(specs, platform, force_ruby: force_ruby, prefer_locked: prefer_locked) sort_and_filter_best_platform_match(matching, platform) end |
permalink .sort_and_filter_best_platform_match(matching, platform) ⇒ Object
[View source]
73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/bundler/gem_helpers.rb', line 73 def sort_and_filter_best_platform_match(matching, platform) return matching if matching.one? exact = matching.select {|spec| spec.platform == platform } return exact if exact.any? sorted_matching = sort_best_platform_match(matching, platform) exemplary_spec = sorted_matching.first sorted_matching.take_while {|spec| same_specificity(platform, spec, exemplary_spec) && same_deps(spec, exemplary_spec) } end |
permalink .sort_best_platform_match(matching, platform) ⇒ Object
[View source]
86 87 88 |
# File 'lib/bundler/gem_helpers.rb', line 86 def sort_best_platform_match(matching, platform) matching.sort_by {|spec| platform_specificity_match(spec.platform, platform) } end |