Replace undef with prepended modules

This commit is contained in:
Douglas Eichelberger 2024-09-05 19:56:32 -07:00
parent 07da4aa7a6
commit 27e951c408
12 changed files with 88 additions and 77 deletions

View File

@ -19,9 +19,6 @@ module Homebrew
sig { returns(T::Array[String]) }
attr_reader :options_only, :flags_only
# undefine tap to allow --tap argument
undef tap
sig { void }
def initialize
require "cli/named_args"

View File

@ -2,8 +2,10 @@
# frozen_string_literal: true
module Homebrew
class Cleanup
undef use_system_ruby?
module CleanupLinux
extend T::Helpers
requires_ancestor { Cleanup }
sig { returns(T::Boolean) }
def use_system_ruby?
@ -21,3 +23,5 @@ module Homebrew
end
end
end
Homebrew::Cleanup.prepend(Homebrew::CleanupLinux)

View File

@ -1,12 +1,10 @@
# typed: true # rubocop:disable Sorbet/StrictSigil
# frozen_string_literal: true
class Formula
undef shared_library
undef loader_path
undef deuniversalize_machos
undef add_global_deps_to_spec
undef valid_platform?
module FormulaLinux
extend T::Helpers
requires_ancestor { Formula }
sig { params(name: String, version: T.nilable(T.any(String, Integer))).returns(String) }
def shared_library(name, version = nil)
@ -50,3 +48,5 @@ class Formula
requirements.none?(MacOSRequirement)
end
end
Formula.prepend(FormulaLinux)

View File

@ -1,16 +1,19 @@
# typed: strict
# typed: true # rubocop:todo Sorbet/StrictSigil
# frozen_string_literal: true
module Homebrew
module CLI
class Parser
undef set_default_options
undef validate_options
module ParserLinux
extend T::Helpers
requires_ancestor { Homebrew::CLI::Parser }
sig { void }
def set_default_options
@args["formula?"] = true if @args.respond_to?(:formula?)
end
sig { void }
def validate_options
return unless @args.respond_to?(:cask?)
return unless @args.cask?
@ -22,3 +25,5 @@ module Homebrew
end
end
end
Homebrew::CLI::Parser.prepend(Homebrew::CLI::ParserLinux)

View File

@ -1,13 +1,13 @@
# typed: strict
# frozen_string_literal: true
class Cleaner
module CleanerMac
private
undef executable_path?
sig { params(path: Pathname).returns(T::Boolean) }
def executable_path?(path)
path.mach_o_executable? || path.text_executable?
end
end
Cleaner.prepend(CleanerMac)

View File

@ -2,9 +2,7 @@
# frozen_string_literal: true
module Homebrew
class Cleanup
undef use_system_ruby?
module CleanupMac
sig { returns(T::Boolean) }
def use_system_ruby?
return false if Homebrew::EnvConfig.force_vendor_ruby?
@ -13,3 +11,5 @@ module Homebrew
end
end
end
Homebrew::Cleanup.prepend(Homebrew::CleanupMac)

View File

@ -3,9 +3,7 @@
module Homebrew
module DevCmd
class Bottle < AbstractCommand
undef tar_args
module BottleMac
sig { returns(T::Array[String]) }
def tar_args
if MacOS.version >= :catalina
@ -15,8 +13,6 @@ module Homebrew
end
end
undef gnu_tar
sig { params(gnu_tar_formula: Formula).returns(String) }
def gnu_tar(gnu_tar_formula)
"#{gnu_tar_formula.opt_bin}/gtar"
@ -24,3 +20,5 @@ module Homebrew
end
end
end
Homebrew::DevCmd::Bottle.prepend(Homebrew::DevCmd::BottleMac)

View File

@ -1,9 +1,10 @@
# typed: strict
# frozen_string_literal: true
class Formula
undef valid_platform?
undef std_cmake_args
module FormulaMac
extend T::Helpers
requires_ancestor { Formula }
sig { returns(T::Boolean) }
def valid_platform?
@ -31,3 +32,5 @@ class Formula
args
end
end
Formula.prepend(FormulaMac)

View File

@ -1,8 +1,10 @@
# typed: strict
# frozen_string_literal: true
class FormulaInstaller
undef fresh_install?
module FormulaInstallerMac
extend T::Helpers
requires_ancestor { FormulaInstaller }
sig { params(formula: Formula).returns(T.nilable(T::Boolean)) }
def fresh_install?(formula)
@ -10,3 +12,5 @@ class FormulaInstaller
(!installed_as_dependency? || !formula.any_version_installed?)
end
end
FormulaInstaller.prepend(FormulaInstallerMac)

View File

@ -1,9 +1,7 @@
# typed: strict
# frozen_string_literal: true
class LinkageChecker
undef system_libraries_exist_in_cache?
module LinkageCheckerMac
private
sig { returns(T::Boolean) }
@ -12,3 +10,5 @@ class LinkageChecker
MacOS.version >= :big_sur
end
end
LinkageChecker.prepend(LinkageCheckerMac)

View File

@ -1,10 +1,12 @@
# typed: strict
# frozen_string_literal: true
module Readall
class << self
undef valid_casks?
module ReadallMac
extend T::Helpers
requires_ancestor { Kernel }
sig { params(tap: Tap, os_name: T.nilable(Symbol), arch: T.nilable(Symbol)).returns(T::Boolean) }
def valid_casks?(tap, os_name: nil, arch: Hardware::CPU.type)
return true if os_name == :linux
@ -36,4 +38,5 @@ module Readall
success
end
end
end
Readall.singleton_class.prepend(ReadallMac)

View File

@ -2,20 +2,17 @@
# frozen_string_literal: true
module Homebrew
class SimulateSystem
class << self
undef simulating_or_running_on_macos?
undef current_os
module SimulateSystemMac
sig { returns(T::Boolean) }
def simulating_or_running_on_macos?
os.blank? || [:macos, *MacOSVersion::SYMBOLS.keys].include?(os)
SimulateSystem.os.blank? || [:macos, *MacOSVersion::SYMBOLS.keys].include?(SimulateSystem.os)
end
sig { returns(Symbol) }
def current_os
os || MacOS.version.to_sym
end
SimulateSystem.os || MacOS.version.to_sym
end
end
end
Homebrew::SimulateSystem.singleton_class.prepend(Homebrew::SimulateSystemMac)