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

.current ⇒ ContextStruct

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:



64
65
66
67
68
69
70
71
72
73
74
# File 'context.rb', line 64

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:



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

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)


77
78
79
# File 'context.rb', line 77

def debug?
  Context.current.debug?
end

#deferred_environment_expansion? ⇒ 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)


92
93
94
# File 'context.rb', line 92

def deferred_environment_expansion?
  Context.current.deferred_environment_expansion?
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)


82
83
84
# File 'context.rb', line 82

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)


87
88
89
# File 'context.rb', line 87

def verbose?
  Context.current.verbose?
end

#with_context(debug: debug?, , quiet: quiet?, , verbose: verbose?, , deferred_environment_expansion: deferred_environment_expansion?, , tolerate_formula_load_errors: Context.current.tolerate_formula_load_errors?, &_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) (defaults to: debug?, )
  • quiet (Boolean) (defaults to: quiet?, )
  • verbose (Boolean) (defaults to: verbose?, )
  • deferred_environment_expansion (Boolean) (defaults to: deferred_environment_expansion?, )
  • tolerate_formula_load_errors (Boolean) (defaults to: Context.current.tolerate_formula_load_errors?)
  • _block (T.proc.void)

Returns:

  • (T.untyped)


106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'context.rb', line 106

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

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