Add resource signature.
This commit is contained in:
parent
dfbf26910d
commit
e39a421bb0
@ -553,7 +553,17 @@ class Formula
|
||||
# ```ruby
|
||||
# resource("additional_files").stage { bin.install "my/extra/tool" }
|
||||
# ```
|
||||
delegate resource: :active_spec
|
||||
#
|
||||
# FIXME: This should not actually take a block. All resources should be defined
|
||||
# at the top-level using {Formula.resource} instead
|
||||
# (see https://github.com/Homebrew/brew/issues/17203#issuecomment-2093654431).
|
||||
#
|
||||
# @api public
|
||||
sig {
|
||||
params(name: String, klass: T.class_of(Resource), block: T.nilable(T.proc.bind(Resource).void))
|
||||
.returns(T.nilable(Resource))
|
||||
}
|
||||
def resource(name, klass = Resource, &block) = active_spec.resource(name, klass, &block)
|
||||
|
||||
# An old name for the formula.
|
||||
sig { returns(T.nilable(String)) }
|
||||
@ -3710,6 +3720,7 @@ class Formula
|
||||
# ```
|
||||
#
|
||||
# @api public
|
||||
sig { params(name: String, klass: T.class_of(Resource), block: T.nilable(T.proc.bind(Resource).void)).void }
|
||||
def resource(name, klass = Resource, &block)
|
||||
specs.each do |spec|
|
||||
spec.resource(name, klass, &block) unless spec.resource_defined?(name)
|
||||
|
||||
@ -123,6 +123,10 @@ class SoftwareSpec
|
||||
resources.key?(name)
|
||||
end
|
||||
|
||||
sig {
|
||||
params(name: String, klass: T.class_of(Resource), block: T.nilable(T.proc.bind(Resource).void))
|
||||
.returns(T.nilable(Resource))
|
||||
}
|
||||
def resource(name, klass = Resource, &block)
|
||||
if block
|
||||
raise DuplicateResourceError, name if resource_defined?(name)
|
||||
@ -132,6 +136,7 @@ class SoftwareSpec
|
||||
|
||||
resources[name] = res
|
||||
dependency_collector.add(res)
|
||||
res
|
||||
else
|
||||
resources.fetch(name) { raise ResourceMissingError.new(owner, name) }
|
||||
end
|
||||
|
||||
@ -80,9 +80,6 @@ class Formula
|
||||
sig { params(args: T.untyped, options: T.untyped, block: T.untyped).returns(T::Boolean) }
|
||||
def loaded_from_api?(*args, **options, &block); end
|
||||
|
||||
sig { params(args: T.untyped, options: T.untyped, block: T.untyped).returns(T.untyped) }
|
||||
def resource(*args, **options, &block); end
|
||||
|
||||
sig { params(args: T.untyped, options: T.untyped, block: T.untyped).returns(T.untyped) }
|
||||
def deps(*args, **options, &block); end
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user