Module: StructuredWarnings::Base::ClassMethods
- Included in:
- StructuredWarnings::Base
- Defined in:
- lib/structured_warnings/base.rb
Overview
This module extends StructuredWarnings::Base and each subclass. It may be used to activate or deactivate a set of warnings.
Instance Method Summary collapse
-
#active? ⇒ Boolean
returns a Boolean, stating whether a warning of this type would be emmitted or not.
-
#disable ⇒ Object
call-seq: disable() disable() ….
-
#enable ⇒ Object
call-seq: enable() enable() ….
Instance Method Details
#active? ⇒ Boolean
returns a Boolean, stating whether a warning of this type would be emmitted or not.
54 55 56 |
# File 'lib/structured_warnings/base.rb', line 54 def active? StructuredWarnings::disabled_warnings.all? {|w| !(w >= self)} end |
#disable ⇒ Object
call-seq:
disable()
disable() {...}
If called without a block, warnings of this type will be disabled in the current thread and all new child threads.
warn("this will be printed") # creates a StructuredWarnings::StandardWarning
# which is enabled by default
StructuredWarnings::Base.disable
warn("this will not be printed") # creates a StructuredWarnings::StandardWarning
# which is currently disabled
If called with a block, warnings of this type will be disabled in the dynamic scope of the given block.
StructuredWarnings::Base.disable do
warn("this will not be printed") # creates a StructuredWarnings::StandardWarning
# which is currently disabled
end
warn("this will be printed") # creates a StructuredWarnings::StandardWarning
# which is currently enabled
83 84 85 86 87 88 89 90 91 |
# File 'lib/structured_warnings/base.rb', line 83 def disable if block_given? StructuredWarnings::with_disabled_warnings(StructuredWarnings.disabled_warnings | [self]) do yield end else StructuredWarnings::disabled_warnings |= [self] end end |
#enable ⇒ Object
call-seq:
enable()
enable() {...}
This method has the same semantics as disable, only with the opposite outcome. In general the last assignment wins, so that disabled warnings may be enabled again and so on.
100 101 102 103 104 105 106 107 108 |
# File 'lib/structured_warnings/base.rb', line 100 def enable if block_given? StructuredWarnings::with_disabled_warnings(StructuredWarnings.disabled_warnings - [self]) do yield end else StructuredWarnings::disabled_warnings -= [self] end end |