Module: Context Private

Overview

This module is part of a private API. This module may only be used in the Homebrew/brew repository. Third parties should avoid using this module if possible, as it may be removed or changed without warning.

Module for querying the current execution context.

Defined Under Namespace

Classes: ContextStruct

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.currentContextStruct

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:



45
46
47
48
49
50
51
52
53
54
55
# File 'context.rb', line 45

def self.current
  current_context = T.cast(Thread.current[:context], T.nilable(ContextStruct))
  return current_context if current_context

  synchronize do
    current = T.let(@current, T.nilable(ContextStruct))
    current ||= ContextStruct.new
    @current = current
    current
  end
end

.current=(context) ⇒ void

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

This method returns an undefined value.

Parameters:



38
39
40
41
42
# File 'context.rb', line 38

def self.current=(context)
  synchronize do
    @current = context
  end
end

Instance Method Details

#debug?Boolean

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:

  • (Boolean)


58
59
60
# File 'context.rb', line 58

def debug?
  Context.current.debug?
end

#quiet?Boolean

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:

  • (Boolean)


63
64
65
# File 'context.rb', line 63

def quiet?
  Context.current.quiet?
end

#verbose?Boolean

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:

  • (Boolean)


68
69
70
# File 'context.rb', line 68

def verbose?
  Context.current.verbose?
end

#with_context(debug: debug?, , quiet: quiet?, , verbose: verbose?, , &_block) ⇒ T.untyped

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Parameters:

  • debug (Boolean, nil) (defaults to: debug?, )
  • quiet (Boolean, nil) (defaults to: quiet?, )
  • verbose (Boolean, nil) (defaults to: verbose?, )
  • _block (T.proc.void)

Returns:

  • (T.untyped)


76
77
78
79
80
81
82
83
84
85
# File 'context.rb', line 76

def with_context(debug: debug?, quiet: quiet?, verbose: verbose?, &_block)
  old_context = Context.current
  Thread.current[:context] = ContextStruct.new(debug:, quiet:, verbose:)

  begin
    yield
  ensure
    Thread.current[:context] = old_context
  end
end