Module: Context Private
- Extended by:
- MonitorMixin
- Included in:
- AbstractDownloadStrategy, Cask::CaskLoader, Cask::Download, Cleaner, Downloadable, Formula, FormulaVersions, Formulary, Formulary::FormulaLoader, GitHubPackages, GitHubReleases, Homebrew, Homebrew::Assertions, Migrator, ObserverPathnameExtension, 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.
16 17 18 19 20 21 22 23 24 |
# File 'context.rb', line 16 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.
10 11 12 13 14 |
# File 'context.rb', line 10 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.
51 52 53 |
# File 'context.rb', line 51 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.
56 57 58 |
# File 'context.rb', line 56 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.
61 62 63 |
# File 'context.rb', line 61 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.
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'context.rb', line 65 def with_context(**) old_context = Context.current 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 begin yield ensure Thread.current[:context] = old_context end end |