mirror of
https://github.com/Homebrew/brew.git
synced 2025-07-14 16:09:03 +08:00
Inline use of attr_rw
This commit is contained in:
parent
58e4e0f8b2
commit
3ef22f3181
@ -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
|
||||
|
@ -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))
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
@ -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
|
@ -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
|
@ -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
|
@ -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
|
||||
|
@ -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
|
@ -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
|
@ -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
|
@ -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
|
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user