Module: Context Private

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Module for querying the current execution context.

Defined Under Namespace

Classes: ContextStruct

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.currentObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



17
18
19
20
21
22
23
24
25
# File 'brew/Library/Homebrew/context.rb', line 17

def self.current
  if current_context = Thread.current[:context]
    return current_context
  end

  synchronize do
    @current ||= ContextStruct.new
  end
end

.current=(context) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



11
12
13
14
15
# File 'brew/Library/Homebrew/context.rb', line 11

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

Instance Method Details

#debug?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


48
49
50
# File 'brew/Library/Homebrew/context.rb', line 48

def debug?
  Context.current.debug?
end

#quiet?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


52
53
54
# File 'brew/Library/Homebrew/context.rb', line 52

def quiet?
  Context.current.quiet?
end

#verbose?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


56
57
58
# File 'brew/Library/Homebrew/context.rb', line 56

def verbose?
  Context.current.verbose?
end

#with_context(**options) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'brew/Library/Homebrew/context.rb', line 60

def with_context(**options)
  old_context = Thread.current[:context]

  new_context = ContextStruct.new(
    debug:   options.fetch(:debug, old_context&.debug?),
    quiet:   options.fetch(:quiet, old_context&.quiet?),
    verbose: options.fetch(:verbose, old_context&.verbose?),
  )

  Thread.current[:context] = new_context

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