Module: Context Private
- Extended by:
- MonitorMixin
- Included in:
- AbstractDownloadStrategy, Bintray, Cask::Cmd, Cleaner, Formula, FormulaVersions, Formulary::FormulaLoader, Homebrew, Homebrew::Assertions, Migrator, Resource, SystemCommand, SystemCommand::Result, Utils::Analytics
- Defined in:
- Library/Homebrew/context.rb
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
- .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. You should avoid using this method if possible, as it may be removed or be changed in the future.
18 19 20 21 22 23 24 25 26 |
# File 'Library/Homebrew/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. You should avoid using this method if possible, as it may be removed or be changed in the future.
12 13 14 15 16 |
# File 'Library/Homebrew/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. You should avoid using this method if possible, as it may be removed or be changed in the future.
49 50 51 |
# File 'Library/Homebrew/context.rb', line 49 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.
53 54 55 |
# File 'Library/Homebrew/context.rb', line 53 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.
57 58 59 |
# File 'Library/Homebrew/context.rb', line 57 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.
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'Library/Homebrew/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 |