Module: Context Private
- Extended by:
- MonitorMixin
- Included in:
- AbstractDownloadStrategy, Cask::Cmd, Cask::Download, Cleaner, Formula, FormulaVersions, Formulary::FormulaLoader, GitHubPackages, GitHubReleases, Homebrew, Homebrew::Assertions, Migrator, Resource, SystemCommand, SystemCommand::Result, Utils::Analytics
- Defined in:
- context.rb
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
-
.current ⇒ Object
private
-
.current=(context) ⇒ Object
private
Instance Method Summary collapse
-
#debug? ⇒ Boolean
private
-
#quiet? ⇒ Boolean
private
-
#verbose? ⇒ Boolean
private
-
#with_context(**options) ⇒ Object
private
Class Method Details
.current ⇒ Object
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.
18 19 20 21 22 23 24 25 26 |
# File 'context.rb', line 18 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. 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.
12 13 14 15 16 |
# File 'context.rb', line 12 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.
49 50 51 |
# File 'context.rb', line 49 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.
53 54 55 |
# File 'context.rb', line 53 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.
57 58 59 |
# File 'context.rb', line 57 def verbose? Context.current.verbose? end |
#with_context(**options) ⇒ Object
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.
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'context.rb', line 61 def with_context(**) old_context = Thread.current[:context] new_context = ContextStruct.new( debug: .fetch(:debug, old_context&.debug?), quiet: .fetch(:quiet, old_context&.quiet?), verbose: .fetch(:verbose, old_context&.verbose?), ) Thread.current[:context] = new_context yield ensure Thread.current[:context] = old_context end |