Skip to content

Commit 050dce7

Browse files
Refactor some stuff
1 parent 5dbc882 commit 050dce7

File tree

8 files changed

+17
-8
lines changed

8 files changed

+17
-8
lines changed

bundler/lib/bundler/cli/common.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def self.output_fund_metadata_summary
2020
current_dependencies = definition.requested_dependencies
2121
current_specs = definition.specs
2222

23-
count = current_dependencies.count {|dep| current_specs[dep.name].first.metadata.key?("funding_uri") }
23+
count = current_dependencies.count {|dep| current_specs.find_by_name(dep.name).metadata.key?("funding_uri") }
2424

2525
return if count.zero?
2626

bundler/lib/bundler/cli/fund.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def run
2020
end
2121

2222
fund_info = deps.each_with_object([]) do |dep, arr|
23-
spec = Bundler.definition.specs[dep.name].first
23+
spec = Bundler.definition.specs.find_by_name(dep.name)
2424
if spec.metadata.key?("funding_uri")
2525
arr << "* #{spec.name} (#{spec.version})\n Funding: #{spec.metadata["funding_uri"]}"
2626
end

bundler/lib/bundler/cli/update.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ def run
9090
next unless locked_info
9191

9292
locked_spec = locked_info[:spec]
93-
new_spec = Bundler.definition.specs[name].first
93+
new_spec = Bundler.definition.specs.find_by_name(name)
9494
unless new_spec
9595
unless locked_spec.match_platform(Bundler.local_platform)
9696
Bundler.ui.warn "Bundler attempted to update #{name} but it was not considered because it is for a different platform from the current one"

bundler/lib/bundler/definition.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,7 @@ def materialize(dependencies)
577577
def start_resolution
578578
result = SpecSet.new(resolver.start)
579579

580-
@resolved_bundler_version = result.find {|spec| spec.name == "bundler" }&.version
580+
@resolved_bundler_version = result.find_version("bundler")
581581
@platforms = result.complete_platforms!(platforms) if should_complete_platforms?
582582

583583
SpecSet.new(result.for(dependencies, false, @platforms))

bundler/lib/bundler/installer.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,9 @@ def generate_bundler_executable_stubs(spec, options = {})
9999
if options[:binstubs_cmd] && spec.executables.empty?
100100
options = {}
101101
spec.runtime_dependencies.each do |dep|
102-
bins = @definition.specs[dep].first.executables
103-
options[dep.name] = bins unless bins.empty?
102+
name = dep.name
103+
bins = @definition.specs.find_by_name(name).executables
104+
options[name] = bins unless bins.empty?
104105
end
105106
if options.any?
106107
Bundler.ui.warn "#{spec.name} has no executables, but you may want " \

bundler/lib/bundler/resolver/package.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class Package
1818
def initialize(name, platforms, locked_specs:, unlock:, prerelease: false, dependency: nil)
1919
@name = name
2020
@platforms = platforms
21-
@locked_version = locked_specs[name].first&.version
21+
@locked_version = locked_specs.find_version(name)
2222
@unlock = unlock
2323
@dependency = dependency || Dependency.new(name, @locked_version)
2424
@top_level = !dependency.nil?

bundler/lib/bundler/spec_set.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,14 @@ def complete_platforms!(platforms)
9090
platforms
9191
end
9292

93+
def find_by_name(name)
94+
self[name].first
95+
end
96+
97+
def find_version(name)
98+
find_by_name(name)&.version
99+
end
100+
93101
def [](key)
94102
key = key.name if key.respond_to?(:name)
95103
lookup[key]&.reverse || []

bundler/spec/commands/pristine_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@
215215

216216
def find_spec(name)
217217
without_env_side_effects do
218-
Bundler.definition.specs[name].first
218+
Bundler.definition.specs.find_by_name(name)
219219
end
220220
end
221221
end

0 commit comments

Comments
 (0)