Class: Klogger::GroupSet

Inherits:
Object
  • Object
show all
Defined in:
lib/klogger/group_set.rb

Instance Method Summary collapse

Constructor Details

#initializeGroupSet

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(**tags)
  id = SecureRandom.hex(4)
  @groups.value += [{ id: id, tags: tags }]
  id
end

#add_without_id(**tags) ⇒ Object



36
37
38
39
# File 'lib/klogger/group_set.rb', line 36

def add_without_id(**tags)
  @groups.value += [{ tags: tags }]
  nil
end

#call(**tags) ⇒ Object



23
24
25
26
27
28
# File 'lib/klogger/group_set.rb', line 23

def call(**tags)
  add(**tags)
  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(**tags)
  add_without_id(**tags)
  yield
ensure
  pop
end

#groupsObject



12
13
14
# File 'lib/klogger/group_set.rb', line 12

def groups
  @groups.value
end

#popObject



41
42
43
# File 'lib/klogger/group_set.rb', line 41

def pop
  @groups.value.pop
end