Skip to content

Commit f8d82c0

Browse files
authored
Merge pull request #20728 from Homebrew/cask_dsl_types
cask/dsl: add some Sorbet types.
2 parents f175ca5 + 7013a2f commit f8d82c0

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

Library/Homebrew/cask/dsl/base.rb

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# typed: true # rubocop:todo Sorbet/StrictSigil
1+
# typed: strict
22
# frozen_string_literal: true
33

44
require "cask/utils"
@@ -10,20 +10,23 @@ class DSL
1010
class Base
1111
extend Forwardable
1212

13+
sig { params(cask: Cask, command: T.class_of(SystemCommand)).void }
1314
def initialize(cask, command = SystemCommand)
14-
@cask = cask
15-
@command = command
15+
@cask = T.let(cask, Cask)
16+
@command = T.let(command, T.class_of(SystemCommand))
1617
end
1718

1819
def_delegators :@cask, :token, :version, :caskroom_path, :staged_path, :appdir, :language, :arch
1920

21+
sig { params(executable: String, options: T.untyped).returns(T.nilable(SystemCommand::Result)) }
2022
def system_command(executable, **options)
2123
@command.run!(executable, **options)
2224
end
2325

2426
# No need to define it as it's the default/superclass implementation.
2527
# rubocop:disable Style/MissingRespondToMissing
26-
def method_missing(method, *)
28+
sig { params(method: T.nilable(Symbol), args: T.untyped).returns(T.nilable(Object)) }
29+
def method_missing(method, *args)
2730
if method
2831
underscored_class = T.must(self.class.name).gsub(/([[:lower:]])([[:upper:]][[:lower:]])/, '\1_\2').downcase
2932
section = underscored_class.split("::").last

Library/Homebrew/cask/dsl/caveats.rb

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,12 @@ class DSL
1313
# to the output by the caller, but that feature is only for the
1414
# convenience of cask authors.
1515
class Caveats < Base
16+
sig { params(args: T.anything).void }
1617
def initialize(*args)
1718
super
18-
@built_in_caveats = {}
19-
@custom_caveats = []
20-
@discontinued = false
19+
@built_in_caveats = T.let({}, T::Hash[Symbol, String])
20+
@custom_caveats = T.let([], T::Array[String])
21+
@discontinued = T.let(false, T::Boolean)
2122
end
2223

2324
def self.caveat(name, &block)
@@ -40,11 +41,13 @@ def to_s
4041
end
4142

4243
# Override `puts` to collect caveats.
44+
sig { params(args: String).returns(Symbol) }
4345
def puts(*args)
4446
@custom_caveats += args
4547
:built_in_caveat
4648
end
4749

50+
sig { params(block: T.proc.returns(T.nilable(T.any(Symbol, String)))).void }
4851
def eval_caveats(&block)
4952
result = instance_eval(&block)
5053
return unless result

0 commit comments

Comments
 (0)