Class: Tag::GlobalState
- Inherits:
-
Object
- Object
- Tag::GlobalState
- Defined in:
- lib/dbg_tags.rb
Overview
This class stores an instance of the global state of the Tag system
Instance Attribute Summary collapse
- #enabled ⇒ {Symbol} => 0..5 readonly
-
#inside ⇒ Bool
(also: #inside?)
True if a Tag.err..dtl is currently active.
-
#stream ⇒ IO
Current output stream.
Instance Method Summary collapse
-
#enable(*features, **opts) ⇒ Object
A block can be given to restore the original state afterwards enable :feature, …[, feature: level, …] [block] :generic is NO LONGER IMPLICETELY ENABLED as of version 1.0.0 Use :all to set a default for all features not mentioned otherwise Integers in range 1..5 can be used as level or the constants ERR,LOG,TRC,VAL,DTL or the symbols :err, :log, :trc, :val and :dtl Strings can be used in the shape of ‘err’ or ‘>=err’ etc.
-
#level(feature) ⇒ 0..5
Current effective level for feature.
-
#restore_state(state) ⇒ Object
A block can be given to restore the original state afterwards.
Instance Attribute Details
#enabled ⇒ {Symbol} => 0..5 (readonly)
109 110 111 |
# File 'lib/dbg_tags.rb', line 109 def enabled @enabled end |
#inside ⇒ Bool Also known as: inside?
Returns True if a Tag.err..dtl is currently active.
112 113 114 |
# File 'lib/dbg_tags.rb', line 112 def inside @inside end |
#stream ⇒ IO
Returns Current output stream.
116 117 118 |
# File 'lib/dbg_tags.rb', line 116 def stream @stream end |
Instance Method Details
#enable(*features, **opts) ⇒ Object
A block can be given to restore the original state afterwards enable :feature, …[, feature: level, …] [block] :generic is NO LONGER IMPLICETELY ENABLED as of version 1.0.0 Use :all to set a default for all features not mentioned otherwise Integers in range 1..5 can be used as level or the constants ERR,LOG,TRC,VAL,DTL or the symbols :err, :log, :trc, :val and :dtl Strings can be used in the shape of ‘err’ or ‘>=err’ etc. If ‘>=LVL’ is used the level will not lower, if already set in an outer block. If no level is specified for a feature the default is :trc (== TRC == 3) use nil, :nil, :none or Tag::NONE to disable all tags, even the ERR level ones.
enable performs a merge with an existing enable.
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
# File 'lib/dbg_tags.rb', line 132 def enable *features, **opts org_enabled = @enabled.clone # to restore the state at the end (unused unless block_given) features.each do |feature| case feature when 0..5 # not a feature, apply to :generic @enabled[TAG_FEATURE_GENERIC] = feature when Symbol if TAG_MAPPING[feature] # not a feature @enabled[TAG_FEATURE_GENERIC] = TAG_MAPPING[feature] else @enabled[feature] = TAG_DEFAULT_LEVEL end when String @enabled[TAG_FEATURE_GENERIC] = debunk_level feature, TAG_FEATURE_GENERIC else raise ArgumentError "bad level #{feature.inspect}" end # case end # each opts.each do |feature, level| # OK STDERR.puts "OPTION!!!!!!!!!!!!!!!!!, calling debunk_level" @enabled[feature] = debunk_level level, feature end if features.empty? && opts.empty? @enabled[TAG_FEATURE_GENERIC] = TAG_DEFAULT_LEVEL end if block_given? begin yield ensure @enabled = org_enabled end # ensure end # block_given? end |
#level(feature) ⇒ 0..5
Returns Current effective level for feature.
183 184 185 |
# File 'lib/dbg_tags.rb', line 183 def level feature @enabled[feature] || @enabled[TAG_FEATURE_ALL] || Tag::NONE end |
#restore_state(state) ⇒ Object
A block can be given to restore the original state afterwards. restore_state overwrites any existing enabled feature.
169 170 171 172 173 174 175 176 177 178 179 |
# File 'lib/dbg_tags.rb', line 169 def restore_state state org_enabled = @enabled.clone # to restore the state at the end (unused unless block_given) @enabled = state.dup if block_given? begin yield ensure @enabled = org_enabled end # ensure end # block_given? end |