Class: Klogger::GroupSet
- Inherits:
-
Object
- Object
- Klogger::GroupSet
- Defined in:
- lib/klogger/group_set.rb
Instance Method Summary collapse
- #add(**tags) ⇒ Object
- #add_without_id(**tags) ⇒ Object
- #call(**tags) ⇒ Object
- #call_without_id(**tags) ⇒ Object
- #groups ⇒ Object
-
#initialize ⇒ GroupSet
constructor
A new instance of GroupSet.
- #pop ⇒ Object
Constructor Details
#initialize ⇒ GroupSet
Returns a new instance of GroupSet.
8 9 10 |
# File 'lib/klogger/group_set.rb', line 8 def initialize @groups = Concurrent::ThreadLocalVar.new { [] } end |
Instance Method Details
#add(**tags) ⇒ Object
30 31 32 33 34 |
# File 'lib/klogger/group_set.rb', line 30 def add(**) id = SecureRandom.hex(4) @groups.value += [{ id: id, tags: }] id end |
#add_without_id(**tags) ⇒ Object
36 37 38 39 |
# File 'lib/klogger/group_set.rb', line 36 def add_without_id(**) @groups.value += [{ tags: }] nil end |
#call(**tags) ⇒ Object
23 24 25 26 27 28 |
# File 'lib/klogger/group_set.rb', line 23 def call(**) add(**) yield ensure pop end |
#call_without_id(**tags) ⇒ Object
16 17 18 19 20 21 |
# File 'lib/klogger/group_set.rb', line 16 def call_without_id(**) add_without_id(**) yield ensure pop end |
#groups ⇒ Object
12 13 14 |
# File 'lib/klogger/group_set.rb', line 12 def groups @groups.value end |
#pop ⇒ Object
41 42 43 |
# File 'lib/klogger/group_set.rb', line 41 def pop @groups.value.pop end |