Merge pull request #12664 from MikeMcQuaid/formula_cask_compat
Start process to remove `Enumerable` from `Formula` and `Cask::Cask`.
This commit is contained in:
commit
cfd9d9d566
@ -15,21 +15,20 @@ module Cask
|
||||
class Cask
|
||||
extend T::Sig
|
||||
|
||||
extend Enumerable
|
||||
extend Forwardable
|
||||
extend Searchable
|
||||
include Metadata
|
||||
|
||||
attr_reader :token, :sourcefile_path, :source, :config, :default_config
|
||||
|
||||
def self.each(&block)
|
||||
return to_enum unless block
|
||||
|
||||
Tap.flat_map(&:cask_files).each do |f|
|
||||
yield CaskLoader::FromTapPathLoader.new(f).load(config: nil)
|
||||
def self.all
|
||||
Tap.flat_map(&:cask_files).map do |f|
|
||||
CaskLoader::FromTapPathLoader.new(f).load(config: nil)
|
||||
rescue CaskUnreadableError => e
|
||||
opoo e.message
|
||||
end
|
||||
|
||||
nil
|
||||
end.compact
|
||||
end
|
||||
|
||||
def tap
|
||||
|
||||
@ -121,7 +121,7 @@ module Homebrew
|
||||
puts_deps_tree dependents, recursive: recursive, args: args
|
||||
return
|
||||
elsif args.all?
|
||||
puts_deps sorted_dependents(Formula.to_a + Cask::Cask.to_a), recursive: recursive, args: args
|
||||
puts_deps sorted_dependents(Formula.all + Cask::Cask.all), recursive: recursive, args: args
|
||||
return
|
||||
elsif !args.no_named? && args.for_each?
|
||||
puts_deps sorted_dependents(args.named.to_formulae_and_casks), recursive: recursive, args: args
|
||||
|
||||
@ -207,7 +207,7 @@ module Homebrew
|
||||
end
|
||||
when :v2
|
||||
formulae, casks = if args.all?
|
||||
[Formula.sort, Cask::Cask.to_a.sort_by(&:full_name)]
|
||||
[Formula.sort, Cask::Cask.all.sort_by(&:full_name)]
|
||||
elsif args.installed?
|
||||
[Formula.installed.sort, Cask::Caskroom.casks.sort_by(&:full_name)]
|
||||
else
|
||||
|
||||
@ -34,7 +34,7 @@ module Homebrew
|
||||
args = options_args.parse
|
||||
|
||||
if args.all?
|
||||
puts_options Formula.to_a.sort, args: args
|
||||
puts_options Formula.all.sort, args: args
|
||||
elsif args.installed?
|
||||
puts_options Formula.installed.sort, args: args
|
||||
elsif args.command.present?
|
||||
|
||||
@ -593,6 +593,7 @@ class ReporterHub
|
||||
private
|
||||
|
||||
def dump_formula_report(key, title)
|
||||
# TODO: 3.4.0: odisabled the old functionality and make this default
|
||||
only_installed = Homebrew::EnvConfig.update_report_only_installed?
|
||||
|
||||
formulae = select_formula(key).sort.map do |name, new_name|
|
||||
|
||||
@ -101,10 +101,10 @@ module Homebrew
|
||||
deps
|
||||
else
|
||||
if show_formulae_and_casks || args.formula?
|
||||
deps += args.installed? ? Formula.installed : Formula.to_a
|
||||
deps += args.installed? ? Formula.installed : Formula.all
|
||||
end
|
||||
if show_formulae_and_casks || args.cask?
|
||||
deps += args.installed? ? Cask::Caskroom.casks : Cask::Cask.to_a
|
||||
deps += args.installed? ? Cask::Caskroom.casks : Cask::Cask.all
|
||||
end
|
||||
|
||||
select_used_dependents(dependents(deps), used_formulae, recursive, includes, ignores)
|
||||
|
||||
21
Library/Homebrew/compat/cask.rb
Normal file
21
Library/Homebrew/compat/cask.rb
Normal file
@ -0,0 +1,21 @@
|
||||
# typed: true
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Cask
|
||||
class Cask
|
||||
extend Enumerable
|
||||
|
||||
def self.each(&block)
|
||||
# TODO: 3.4.0: odeprecated "`Enumerable` methods on `Cask::Cask`",
|
||||
# "`Cask::Cask.all` (but avoid looping over all casks, it's slow and insecure)"
|
||||
|
||||
return to_enum unless block
|
||||
|
||||
Tap.flat_map(&:cask_files).each do |f|
|
||||
yield CaskLoader::FromTapPathLoader.new(f).load(config: nil)
|
||||
rescue CaskUnreadableError => e
|
||||
opoo e.message
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
20
Library/Homebrew/compat/formula.rb
Normal file
20
Library/Homebrew/compat/formula.rb
Normal file
@ -0,0 +1,20 @@
|
||||
# typed: true
|
||||
# frozen_string_literal: true
|
||||
|
||||
class Formula
|
||||
extend Enumerable
|
||||
|
||||
def self.each(&_block)
|
||||
# TODO: 3.4.0: odeprecated "`Enumerable` methods on `Formula`",
|
||||
# "`Formula.all` (but avoid looping over all formulae, it's slow and insecure)"
|
||||
|
||||
files.each do |file|
|
||||
yield Formulary.factory(file)
|
||||
rescue FormulaUnavailableError, FormulaUnreadableError => e
|
||||
# Don't let one broken formula break commands. But do complain.
|
||||
onoe "Failed to import: #{file}"
|
||||
$stderr.puts e
|
||||
next
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -1,2 +1,5 @@
|
||||
# typed: strict
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "compat/formula"
|
||||
require "compat/cask"
|
||||
|
||||
@ -36,7 +36,7 @@ class DescriptionCacheStore < CacheStore
|
||||
def populate_if_empty!
|
||||
return unless database.empty?
|
||||
|
||||
Formula.each { |f| update!(f.full_name, f.desc) }
|
||||
Formula.all.each { |f| update!(f.full_name, f.desc) }
|
||||
end
|
||||
|
||||
# Use an update report to update the {DescriptionCacheStore}.
|
||||
|
||||
@ -121,7 +121,7 @@ module Homebrew
|
||||
end
|
||||
elsif args.no_named?
|
||||
no_named_args = true
|
||||
[Formula, Cask::Cask.to_a]
|
||||
[Formula.all, Cask::Cask.all]
|
||||
else
|
||||
args.named.to_formulae_and_casks
|
||||
.partition { |formula_or_cask| formula_or_cask.is_a?(Formula) }
|
||||
|
||||
@ -367,7 +367,7 @@ module Homebrew
|
||||
base_url = url_split.first(components_to_match).join("/")
|
||||
base_url = /#{Regexp.escape(base_url)}/
|
||||
guesses = []
|
||||
Formula.each do |f|
|
||||
Formula.all.each do |f|
|
||||
guesses << f if f.stable&.url&.match(base_url)
|
||||
end
|
||||
return guesses.shift if guesses.count == 1
|
||||
|
||||
@ -71,8 +71,8 @@ module Homebrew
|
||||
casks = args.formula? ? [] : Cask::Caskroom.casks
|
||||
formulae + casks
|
||||
elsif args.all?
|
||||
formulae = args.cask? ? [] : Formula.to_a
|
||||
casks = args.formula? ? [] : Cask::Cask.to_a
|
||||
formulae = args.cask? ? [] : Formula.all
|
||||
casks = args.formula? ? [] : Cask::Cask.all
|
||||
formulae + casks
|
||||
elsif args.named.present?
|
||||
if args.formula?
|
||||
|
||||
@ -79,9 +79,9 @@ module Homebrew
|
||||
if args.named.present?
|
||||
formulae = all_formulae = args.named.to_formulae
|
||||
elsif args.total?
|
||||
formulae = all_formulae = Formula.to_a
|
||||
formulae = all_formulae = Formula.all
|
||||
elsif args.dependents?
|
||||
formulae = all_formulae = Formula.to_a
|
||||
formulae = all_formulae = Formula.all
|
||||
|
||||
@sort = " (sorted by number of dependents)"
|
||||
else
|
||||
|
||||
@ -15,7 +15,7 @@ module Homebrew
|
||||
return if args.formula?
|
||||
|
||||
ohai "Casks"
|
||||
Cask::Cask.to_a.extend(Searchable)
|
||||
Cask::Cask.all.extend(Searchable)
|
||||
.search(string_or_regex, &:name)
|
||||
.each do |cask|
|
||||
puts "#{Tty.bold}#{cask.token}:#{Tty.reset} #{cask.name.join(", ")}"
|
||||
|
||||
@ -64,8 +64,7 @@ class Formula
|
||||
include Utils::Shebang
|
||||
include Utils::Shell
|
||||
include Context
|
||||
include OnOS # TODO: 3.3.0: deprecate OnOS usage in instance methods.
|
||||
extend Enumerable
|
||||
include OnOS # TODO: 3.4.0: odeprecate OnOS usage in instance methods.
|
||||
extend Forwardable
|
||||
extend Cachable
|
||||
extend Predicable
|
||||
@ -1682,16 +1681,18 @@ class Formula
|
||||
@full_names ||= core_names + tap_names
|
||||
end
|
||||
|
||||
# an array of all {Formula}
|
||||
# @private
|
||||
def self.each(&_block)
|
||||
files.each do |file|
|
||||
yield Formulary.factory(file)
|
||||
def self.all
|
||||
files.map do |file|
|
||||
Formulary.factory(file)
|
||||
rescue FormulaUnavailableError, FormulaUnreadableError => e
|
||||
# Don't let one broken formula break commands. But do complain.
|
||||
onoe "Failed to import: #{file}"
|
||||
$stderr.puts e
|
||||
next
|
||||
end
|
||||
|
||||
nil
|
||||
end.compact
|
||||
end
|
||||
|
||||
# An array of all racks currently installed.
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user