Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions Library/Homebrew/cask/dsl/base.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# typed: true # rubocop:todo Sorbet/StrictSigil
# typed: strict
# frozen_string_literal: true

require "cask/utils"
Expand All @@ -10,20 +10,23 @@ class DSL
class Base
extend Forwardable

sig { params(cask: Cask, command: T.class_of(SystemCommand)).void }
def initialize(cask, command = SystemCommand)
@cask = cask
@command = command
@cask = T.let(cask, Cask)
@command = T.let(command, T.class_of(SystemCommand))
end

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

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

# No need to define it as it's the default/superclass implementation.
# rubocop:disable Style/MissingRespondToMissing
def method_missing(method, *)
sig { params(method: T.nilable(Symbol), args: T.untyped).returns(T.nilable(Object)) }
def method_missing(method, *args)
if method
underscored_class = T.must(self.class.name).gsub(/([[:lower:]])([[:upper:]][[:lower:]])/, '\1_\2').downcase
section = underscored_class.split("::").last
Expand Down
9 changes: 6 additions & 3 deletions Library/Homebrew/cask/dsl/caveats.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@ class DSL
# to the output by the caller, but that feature is only for the
# convenience of cask authors.
class Caveats < Base
sig { params(args: T.anything).void }
def initialize(*args)
super
@built_in_caveats = {}
@custom_caveats = []
@discontinued = false
@built_in_caveats = T.let({}, T::Hash[Symbol, String])
@custom_caveats = T.let([], T::Array[String])
@discontinued = T.let(false, T::Boolean)
end

def self.caveat(name, &block)
Expand All @@ -40,11 +41,13 @@ def to_s
end

# Override `puts` to collect caveats.
sig { params(args: String).returns(Symbol) }
def puts(*args)
@custom_caveats += args
:built_in_caveat
end

sig { params(block: T.proc.returns(T.nilable(T.any(Symbol, String)))).void }
def eval_caveats(&block)
result = instance_eval(&block)
return unless result
Expand Down