diff --git a/Library/Homebrew/attrable.rb b/Library/Homebrew/attrable.rb index 8dd176ef24..590a6f147d 100644 --- a/Library/Homebrew/attrable.rb +++ b/Library/Homebrew/attrable.rb @@ -18,13 +18,4 @@ module Attrable end end end - - sig { params(attrs: Symbol).void } - def attr_rw(*attrs) - attrs.each do |attr| - define_method attr do |val = nil| - val.nil? ? instance_variable_get(:"@#{attr}") : instance_variable_set(:"@#{attr}", val) - end - end - end end diff --git a/Library/Homebrew/bottle_specification.rb b/Library/Homebrew/bottle_specification.rb index 556659a8ee..352b5149e6 100644 --- a/Library/Homebrew/bottle_specification.rb +++ b/Library/Homebrew/bottle_specification.rb @@ -2,10 +2,8 @@ # frozen_string_literal: true class BottleSpecification - extend Attrable RELOCATABLE_CELLARS = [:any, :any_skip_relocation].freeze - attr_rw :rebuild attr_accessor :tap attr_reader :collector, :root_url_specs, :repository @@ -17,6 +15,11 @@ class BottleSpecification @root_url_specs = {} end + sig { params(val: T.nilable(Integer)).returns(T.nilable(Integer)) } + def rebuild(val = nil) + val.nil? ? @rebuild : @rebuild = val + end + def root_url(var = nil, specs = {}) if var.nil? @root_url ||= if (github_packages_url = GitHubPackages.root_url_if_match(Homebrew::EnvConfig.bottle_domain)) diff --git a/Library/Homebrew/formula.rb b/Library/Homebrew/formula.rb index c8a3e2debe..4faed44b42 100644 --- a/Library/Homebrew/formula.rb +++ b/Library/Homebrew/formula.rb @@ -3374,9 +3374,11 @@ class Formula # desc "Example formula" # ``` # - # @!attribute [w] desc # @api public - attr_rw :desc + sig { params(val: T.nilable(String)).returns(T.nilable(String)) } + def desc(val = nil) + val.nil? ? @desc : @desc = T.let(val, T.nilable(String)) + end # The SPDX ID of the open-source license that the formula uses. # Shows when running `brew info`. @@ -3524,9 +3526,11 @@ class Formula # homepage "https://www.example.com" # ``` # - # @!attribute [w] homepage # @api public - attr_rw :homepage + sig { params(val: T.nilable(String)).returns(T.nilable(String)) } + def homepage(val = nil) + val.nil? ? @homepage : @homepage = T.let(val, T.nilable(String)) + end # Checks whether a `livecheck` specification is defined or not. # @@ -3566,7 +3570,6 @@ class Formula # why they cannot use the bottle. attr_accessor :pour_bottle_check_unsatisfied_reason - # @!attribute [w] revision # Used for creating new Homebrew versions of software without new upstream # versions. For example, if we bump the major version of a library that this # {Formula} {.depends_on} then we may need to update the `revision` of this @@ -3580,9 +3583,11 @@ class Formula # ``` # # @api public - attr_rw :revision + sig { params(val: T.nilable(Integer)).returns(T.nilable(Integer)) } + def revision(val = nil) + val.nil? ? @revision : @revision = T.let(val, T.nilable(Integer)) + end - # @!attribute [w] version_scheme # Used for creating new Homebrew version schemes. For example, if we want # to change version scheme from one to another, then we may need to update # `version_scheme` of this {Formula} to be able to use new version scheme, @@ -3598,7 +3603,10 @@ class Formula # ``` # # @api public - attr_rw :version_scheme + sig { params(val: T.nilable(Integer)).returns(T.nilable(Integer)) } + def version_scheme(val = nil) + val.nil? ? @version_scheme : @version_scheme = T.let(val, T.nilable(Integer)) + end def spec_syms [:stable, :head].freeze diff --git a/Library/Homebrew/requirement.rb b/Library/Homebrew/requirement.rb index b469bcacda..0428e94f2a 100644 --- a/Library/Homebrew/requirement.rb +++ b/Library/Homebrew/requirement.rb @@ -179,11 +179,23 @@ class Requirement class << self include BuildEnvironment::DSL - extend Attrable attr_reader :env_proc, :build - attr_rw :fatal, :cask, :download + sig { params(val: T.nilable(String)).returns(T.nilable(String)) } + def cask(val = nil) + val.nil? ? @cask : @cask = val + end + + sig { params(val: T.nilable(String)).returns(T.nilable(String)) } + def download(val = nil) + val.nil? ? @download : @download = val + end + + sig { params(val: T.nilable(T::Boolean)).returns(T.nilable(T::Boolean)) } + def fatal(val = nil) + val.nil? ? @fatal : @fatal = val + end def satisfy(options = nil, &block) return @satisfied if options.nil? && !block diff --git a/Library/Homebrew/sorbet/rbi/dsl/arch_requirement.rbi b/Library/Homebrew/sorbet/rbi/dsl/arch_requirement.rbi deleted file mode 100644 index 5de043433f..0000000000 --- a/Library/Homebrew/sorbet/rbi/dsl/arch_requirement.rbi +++ /dev/null @@ -1,8 +0,0 @@ -# typed: true - -# DO NOT EDIT MANUALLY -# This is an autogenerated file for dynamic methods in `ArchRequirement`. -# Please instead update this file by running `bin/tapioca dsl ArchRequirement`. - - -class ArchRequirement; end diff --git a/Library/Homebrew/sorbet/rbi/dsl/bottle_specification.rbi b/Library/Homebrew/sorbet/rbi/dsl/bottle_specification.rbi deleted file mode 100644 index d076578f16..0000000000 --- a/Library/Homebrew/sorbet/rbi/dsl/bottle_specification.rbi +++ /dev/null @@ -1,11 +0,0 @@ -# typed: true - -# DO NOT EDIT MANUALLY -# This is an autogenerated file for dynamic methods in `BottleSpecification`. -# Please instead update this file by running `bin/tapioca dsl BottleSpecification`. - - -class BottleSpecification - sig { params(arg: T.untyped).returns(T.untyped) } - def rebuild(arg = nil); end -end diff --git a/Library/Homebrew/sorbet/rbi/dsl/cask_dependent/requirement.rbi b/Library/Homebrew/sorbet/rbi/dsl/cask_dependent/requirement.rbi deleted file mode 100644 index e9718170d2..0000000000 --- a/Library/Homebrew/sorbet/rbi/dsl/cask_dependent/requirement.rbi +++ /dev/null @@ -1,8 +0,0 @@ -# typed: true - -# DO NOT EDIT MANUALLY -# This is an autogenerated file for dynamic methods in `CaskDependent::Requirement`. -# Please instead update this file by running `bin/tapioca dsl CaskDependent::Requirement`. - - -class CaskDependent::Requirement; end diff --git a/Library/Homebrew/sorbet/rbi/dsl/codesign_requirement.rbi b/Library/Homebrew/sorbet/rbi/dsl/codesign_requirement.rbi deleted file mode 100644 index a15cb3779f..0000000000 --- a/Library/Homebrew/sorbet/rbi/dsl/codesign_requirement.rbi +++ /dev/null @@ -1,8 +0,0 @@ -# typed: true - -# DO NOT EDIT MANUALLY -# This is an autogenerated file for dynamic methods in `CodesignRequirement`. -# Please instead update this file by running `bin/tapioca dsl CodesignRequirement`. - - -class CodesignRequirement; end diff --git a/Library/Homebrew/sorbet/rbi/dsl/formula.rbi b/Library/Homebrew/sorbet/rbi/dsl/formula.rbi index 3ced914c9c..c21f24179a 100644 --- a/Library/Homebrew/sorbet/rbi/dsl/formula.rbi +++ b/Library/Homebrew/sorbet/rbi/dsl/formula.rbi @@ -142,22 +142,10 @@ class Formula def version(*args, &block); end class << self - sig { params(arg: T.untyped).returns(T.untyped) } - def desc(arg = nil); end - - sig { params(arg: T.untyped).returns(T.untyped) } - def homepage(arg = nil); end - sig { returns(T::Boolean) } def loaded_from_api?; end sig { returns(T::Boolean) } def on_system_blocks_exist?; end - - sig { params(arg: T.untyped).returns(T.untyped) } - def revision(arg = nil); end - - sig { params(arg: T.untyped).returns(T.untyped) } - def version_scheme(arg = nil); end end end diff --git a/Library/Homebrew/sorbet/rbi/dsl/linux_requirement.rbi b/Library/Homebrew/sorbet/rbi/dsl/linux_requirement.rbi deleted file mode 100644 index 6ad28e5e60..0000000000 --- a/Library/Homebrew/sorbet/rbi/dsl/linux_requirement.rbi +++ /dev/null @@ -1,8 +0,0 @@ -# typed: true - -# DO NOT EDIT MANUALLY -# This is an autogenerated file for dynamic methods in `LinuxRequirement`. -# Please instead update this file by running `bin/tapioca dsl LinuxRequirement`. - - -class LinuxRequirement; end diff --git a/Library/Homebrew/sorbet/rbi/dsl/mac_os_requirement.rbi b/Library/Homebrew/sorbet/rbi/dsl/mac_os_requirement.rbi deleted file mode 100644 index 9e31d54eb8..0000000000 --- a/Library/Homebrew/sorbet/rbi/dsl/mac_os_requirement.rbi +++ /dev/null @@ -1,8 +0,0 @@ -# typed: true - -# DO NOT EDIT MANUALLY -# This is an autogenerated file for dynamic methods in `MacOSRequirement`. -# Please instead update this file by running `bin/tapioca dsl MacOSRequirement`. - - -class MacOSRequirement; end diff --git a/Library/Homebrew/sorbet/rbi/dsl/requirement.rbi b/Library/Homebrew/sorbet/rbi/dsl/requirement.rbi deleted file mode 100644 index e755f8ef24..0000000000 --- a/Library/Homebrew/sorbet/rbi/dsl/requirement.rbi +++ /dev/null @@ -1,19 +0,0 @@ -# typed: true - -# DO NOT EDIT MANUALLY -# This is an autogenerated file for dynamic methods in `Requirement`. -# Please instead update this file by running `bin/tapioca dsl Requirement`. - - -class Requirement - class << self - sig { params(arg: T.untyped).returns(T.untyped) } - def cask(arg = nil); end - - sig { params(arg: T.untyped).returns(T.untyped) } - def download(arg = nil); end - - sig { params(arg: T.untyped).returns(T.untyped) } - def fatal(arg = nil); end - end -end diff --git a/Library/Homebrew/sorbet/rbi/dsl/xcode_requirement.rbi b/Library/Homebrew/sorbet/rbi/dsl/xcode_requirement.rbi deleted file mode 100644 index 6a812e438d..0000000000 --- a/Library/Homebrew/sorbet/rbi/dsl/xcode_requirement.rbi +++ /dev/null @@ -1,8 +0,0 @@ -# typed: true - -# DO NOT EDIT MANUALLY -# This is an autogenerated file for dynamic methods in `XcodeRequirement`. -# Please instead update this file by running `bin/tapioca dsl XcodeRequirement`. - - -class XcodeRequirement; end diff --git a/Library/Homebrew/sorbet/tapioca/compilers/attrables.rb b/Library/Homebrew/sorbet/tapioca/compilers/attrables.rb index a1ae0740f7..d4400d198c 100644 --- a/Library/Homebrew/sorbet/tapioca/compilers/attrables.rb +++ b/Library/Homebrew/sorbet/tapioca/compilers/attrables.rb @@ -28,25 +28,14 @@ module Tapioca sig { params(klass: RBI::Scope, method: T.any(Method, UnboundMethod), class_method: T::Boolean).void } def compile_attrable_method(klass, method, class_method: false) - case method.arity - when -1 - # attr_rw - klass.create_method( - method.name.to_s, - parameters: [create_opt_param("arg", type: "T.untyped", default: "nil")], - return_type: "T.untyped", - class_method:, - ) - when 0 - # attr_predicate - klass.create_method( - method.name.to_s, - return_type: "T::Boolean", - class_method:, - ) - else - raise "Unsupported arity for method #{method.name} - did `Attrable` change?" - end + raise "Unsupported arity for method #{method.name} - did `Attrable` change?" unless method.arity.zero? + + # attr_predicate + klass.create_method( + method.name.to_s, + return_type: "T::Boolean", + class_method:, + ) end end end diff --git a/Library/Homebrew/test/bottle_specification_spec.rb b/Library/Homebrew/test/bottle_specification_spec.rb index cb2c82fd7d..51eed26c67 100644 --- a/Library/Homebrew/test/bottle_specification_spec.rb +++ b/Library/Homebrew/test/bottle_specification_spec.rb @@ -52,11 +52,13 @@ RSpec.describe BottleSpecification do end end - %w[root_url rebuild].each do |method| - specify "##{method}" do - object = Object.new - bottle_spec.public_send(method, object) - expect(bottle_spec.public_send(method)).to eq(object) - end + specify "#rebuild" do + bottle_spec.rebuild(1337) + expect(bottle_spec.rebuild).to eq(1337) + end + + specify "#root_url" do + bottle_spec.root_url("https://example.com") + expect(bottle_spec.root_url).to eq("https://example.com") end end