Class: Hubbado::Log::Tags

Inherits:
Object
  • Object
show all
Defined in:
lib/hubbado/log/tags.rb

Overview

The operator's list, from LOG_TAGS: an allow-list a message's own tags have to intersect before it is written.

Constant Summary collapse

ALL =

Every tag is written, whatever else the list says.

:_all
UNTAGGED =

Messages carrying no tag at all are written. Without it, naming any tag silences them.

:_untagged
EVERY_MESSAGE =

A message marks itself as written whatever the operator asked for.

:*
EXCLUSION =
"-".freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tags = []) ⇒ Tags

Returns a new instance of Tags.



30
31
32
# File 'lib/hubbado/log/tags.rb', line 30

def initialize(tags = [])
  @tags = Array(tags).map { |tag| tag.to_s.to_sym }
end

Instance Attribute Details

#tagsObject (readonly)

Returns the value of attribute tags.



28
29
30
# File 'lib/hubbado/log/tags.rb', line 28

def tags
  @tags
end

Class Method Details

.parse(value) ⇒ Object

Split on commas and nothing else, which is all Eventide's log gem does. Trimming the spaces would be kinder, and would make one LOG_TAGS mean different things in the two gems that share the variable — the divergence this gem cannot afford.



20
21
22
23
24
25
26
# File 'lib/hubbado/log/tags.rb', line 20

def self.parse(value)
  return value if value.is_a?(self)
  return new if value.nil?
  return new(value) if value.is_a?(Array)

  new(value.to_s.split(","))
end

Instance Method Details

#any?Boolean

An exclusion-only list still counts as the operator having named tags, which is what makes -data on its own silence everything rather than subtract from everything.

Returns:

  • (Boolean)


36
37
38
# File 'lib/hubbado/log/tags.rb', line 36

def any?
  !tags.empty?
end

#write?(message_tags) ⇒ Boolean

Branch for branch from Eventide's log gem, so that a string an operator writes means the same thing in both codebases. That includes the awkward part: _all is answered before any exclusion, so _all,-data writes data messages regardless.

Returns:

  • (Boolean)


43
44
45
46
47
48
49
50
51
52
53
# File 'lib/hubbado/log/tags.rb', line 43

def write?(message_tags)
  message_tags = Array(message_tags)

  return true if message_tags.empty? && !any?
  return true if message_tags.include?(EVERY_MESSAGE)
  return true if named?(ALL)
  return true if message_tags.empty? && named?(UNTAGGED)
  return true if !message_tags.empty? && any? && intersect?(message_tags)

  false
end