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.

[View source]

8
9
10
# File 'lib/klogger/group_set.rb', line 8

def initialize
  @groups = Concurrent::ThreadLocalVar.new { [] }
end

Instance Method Details

#add(**tags) ⇒ Object

[View source]

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

[View source]

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

[View source]

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

[View source]

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

[View source]

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

def groups
  @groups.value
end

#popObject

[View source]

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

def pop
  @groups.value.pop
end