Class: Roast::Event

Inherits:
Object
  • Object
show all
Defined in:
lib/roast/event.rb

Constant Summary collapse

LOG_TYPE_KEYS =
[
  :fatal,
  :error,
  :warn,
  :info,
  :debug,
  :unknown,
].freeze
OTHER_TYPE_KEYS =

: Array

[
  :begin,
  :end,
  :stdout,
  :stderr,
  :block,
].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, payload) ⇒ Event

: (Array path, Hash[Symbol, untyped]) -> void



42
43
44
45
46
# File 'lib/roast/event.rb', line 42

def initialize(path, payload)
  @path = path
  @payload = payload
  @time = Time.now
end

Instance Attribute Details

#pathObject (readonly)

: Array



31
32
33
# File 'lib/roast/event.rb', line 31

def path
  @path
end

#payloadObject (readonly)

: Hash[Symbol, untyped] :payload



34
35
36
# File 'lib/roast/event.rb', line 34

def payload
  @payload
end

#timeObject (readonly)

: Time



37
38
39
# File 'lib/roast/event.rb', line 37

def time
  @time
end

Class Method Details

.<<(event) ⇒ Object

: (Hash[Symbol, untyped]) -> void



8
9
10
# File 'lib/roast/event.rb', line 8

def <<(event)
  EventMonitor.accept(Event.new(TaskContext.path, event))
end

Instance Method Details

#log_messageObject

: () -> String



69
70
71
72
73
74
# File 'lib/roast/event.rb', line 69

def log_message
  key = (LOG_TYPE_KEYS & @payload.keys).first
  return "" unless key.present?

  payload[key] || ""
end

#log_severityObject

: () -> Integer



56
57
58
59
60
61
62
63
64
65
66
# File 'lib/roast/event.rb', line 56

def log_severity
  severity = case type
  when :log
    (LOG_TYPE_KEYS & @payload.keys).first || :unknown
  when :stderr
    :warn
  else
    :info
  end
  Logger::Severity.const_get(:LEVELS)[severity.to_s] # rubocop:disable Sorbet/ConstantsFromStrings
end

#typeObject

: () -> Symbol



49
50
51
52
53
# File 'lib/roast/event.rb', line 49

def type
  return :log if (LOG_TYPE_KEYS & @payload.keys).present?

  (OTHER_TYPE_KEYS & @payload.keys).first || :unknown
end