Skip to content

Commit

Permalink
Explicitly mark non-private APIs.
Browse files Browse the repository at this point in the history
  • Loading branch information
reitermarkus committed Apr 22, 2024
1 parent 401500e commit f81aff1
Show file tree
Hide file tree
Showing 19 changed files with 393 additions and 45 deletions.
32 changes: 27 additions & 5 deletions Library/Homebrew/cask/cask.rb
Expand Up @@ -20,7 +20,17 @@ class Cask
extend APIHashable
include Metadata

attr_reader :token, :sourcefile_path, :source, :config, :default_config, :loader
# The token of this {Cask}.
#
# @api public
attr_reader :token

# The config of this {Cask}.
#
# @api internal
attr_reader :config

attr_reader :sourcefile_path, :source, :default_config, :loader
attr_accessor :download, :allow_reassignment

attr_predicate :loaded_from_api?
Expand Down Expand Up @@ -124,13 +134,21 @@ def timestamped_versions(caskroom_path: self.caskroom_path)
.map { |p| p.split.map(&:to_s) }
end

def full_name
# The fully-qualified token of this {Cask}.
#
# @api public
def full_token
return token if tap.nil?
return token if tap.core_cask_tap?

"#{tap.name}/#{token}"
end

# Alias for {#full_token}.
#
# @api internal
def full_name = full_token

sig { returns(T::Boolean) }
def installed?
installed_caskfile&.exist? || false
Expand Down Expand Up @@ -226,6 +244,9 @@ def caskroom_path
@caskroom_path ||= Caskroom.path.join(token)
end

# Check if the installed cask is outdated.
#
# @api internal
def outdated?(greedy: false, greedy_latest: false, greedy_auto_updates: false)
!outdated_version(greedy:, greedy_latest:,
greedy_auto_updates:).nil?
Expand Down Expand Up @@ -304,9 +325,10 @@ def populate_from_api!(json_cask)
@ruby_source_checksum = { sha256: ruby_source_sha256 }
end

def to_s
@token
end
# Alias for {#token}.
#
# @api public
def to_s = token

def inspect
"#<Cask #{token}#{sourcefile_path&.to_s&.prepend(" ")}>"
Expand Down
5 changes: 4 additions & 1 deletion Library/Homebrew/cask/caskroom.rb
Expand Up @@ -6,7 +6,7 @@
module Cask
# Helper functions for interacting with the `Caskroom` directory.
#
# @api private
# @api internal
module Caskroom
sig { returns(Pathname) }
def self.path
Expand Down Expand Up @@ -50,6 +50,9 @@ def self.ensure_caskroom_exists
SystemCommand.run("/usr/bin/chgrp", args: ["admin", path], sudo:)
end

# Get all installed casks.
#
# @api internal
sig { params(config: T.nilable(Config)).returns(T::Array[Cask]) }
def self.casks(config: nil)
tokens.sort.filter_map do |token|
Expand Down
10 changes: 9 additions & 1 deletion Library/Homebrew/cask/config.rb
Expand Up @@ -10,7 +10,7 @@
module Cask
# Configuration for installing casks.
#
# @api private
# @api internal
class Config
DEFAULT_DIRS = {
appdir: "/Applications",
Expand Down Expand Up @@ -88,6 +88,9 @@ def self.canonicalize(config)
end
end

# Get the explicit configuration.
#
# @api internal
sig { returns(T::Hash[Symbol, T.any(String, Pathname, T::Array[String])]) }
attr_accessor :explicit

Expand Down Expand Up @@ -184,6 +187,11 @@ def merge(other)
self.class.new(explicit: other.explicit.merge(explicit))
end

# Get explicit configuration as a string.
#
# @api internal
#
# TODO: This is only used by `homebrew/bundle`, so move it there.
sig { returns(String) }
def explicit_s
explicit.map do |key, value|
Expand Down
3 changes: 3 additions & 0 deletions Library/Homebrew/development_tools.rb
Expand Up @@ -83,6 +83,9 @@ def llvm_clang_build_version
end
end

# Get the GCC version.
#
# @api internal
sig { params(cc: String).returns(Version) }
def gcc_version(cc)
(@gcc_version ||= {}).fetch(cc) do
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/env_config.rb
Expand Up @@ -6,7 +6,7 @@
module Homebrew
# Helper module for querying Homebrew-specific environment variables.
#
# @api private
# @api internal
module EnvConfig
module_function

Expand Down
4 changes: 4 additions & 0 deletions Library/Homebrew/exceptions.rb
Expand Up @@ -5,6 +5,8 @@
require "utils"

# Raised when a command is used wrong.
#
# @api internal
class UsageError < RuntimeError
attr_reader :reason

Expand Down Expand Up @@ -133,6 +135,8 @@ def to_s
end

# Raised when a formula is not available.
#
# @api internal
class FormulaUnavailableError < FormulaOrCaskUnavailableError
attr_accessor :dependent

Expand Down
18 changes: 16 additions & 2 deletions Library/Homebrew/extend/kernel.rb
Expand Up @@ -58,31 +58,42 @@ def oh1(title, truncate: :auto)
puts oh1_title(title, truncate:)
end

# Print a message prefixed with "Warning" (do this rarely).
# Print a warning message.
#
# @api public
def opoo(message)
Tty.with($stderr) do |stderr|
stderr.puts Formatter.warning(message, label: "Warning")
end
end

# Print a message prefixed with "Error".
# Print an error message.
#
# @api public
def onoe(message)
Tty.with($stderr) do |stderr|
stderr.puts Formatter.error(message, label: "Error")
end
end

# Print an error message and fail at the end of the program.
#
# @api public
def ofail(error)
onoe error
Homebrew.failed = true
end

# Print an error message and fail immediately.
#
# @api public
sig { params(error: T.any(String, Exception)).returns(T.noreturn) }
def odie(error)
onoe error
exit 1
end

# Output a deprecation warning/error message.
def odeprecated(method, replacement = nil,
disable: false,
disable_on: nil,
Expand Down Expand Up @@ -254,6 +265,9 @@ def quiet_system(cmd, *args)
end
end

# Find a command.
#
# @api public
def which(cmd, path = ENV.fetch("PATH"))
PATH.new(path).each do |p|
begin
Expand Down

0 comments on commit f81aff1

Please sign in to comment.