Skip to content

Commit 9eee887

Browse files
Refactor some stuff
1 parent 38ab890 commit 9eee887

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
@@ -581,7 +581,7 @@ def materialize(dependencies)
581581
def start_resolution
582582
result = SpecSet.new(resolver.start)
583583

584-
@resolved_bundler_version = result.find {|spec| spec.name == "bundler" }&.version
584+
@resolved_bundler_version = result.find_version("bundler")
585585

586586
@platforms = if should_complete_platforms?
587587
result.complete_platforms!(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
@prerelease = @dependency.prerelease? || @locked_version&.prerelease? || prerelease ? :consider_first : :ignore

bundler/lib/bundler/spec_set.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,14 @@ def cleanup_platforms!(deps, platforms)
104104
end
105105
end
106106

107+
def find_by_name(name)
108+
self[name].first
109+
end
110+
111+
def find_version(name)
112+
find_by_name(name)&.version
113+
end
114+
107115
def [](key)
108116
key = key.name if key.respond_to?(:name)
109117
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)