Module: Solid::Process::EventLogs::BasicLoggerListener::MessagesNesting

Defined in:
lib/solid/process/event_logs/basic_logger_listener.rb

Constant Summary collapse

MAP_STEP_METHOD =
lambda do |record_result|
  kind, type, value = record_result.values_at(:kind, :type, :value)

  value_keys = "#{value.keys.join(":, ")}:"
  value_keys = "" if value_keys == ":"

  case type
  when :_given_ then "Given(#{value_keys})"
  when :_continue_ then "Continue(#{value_keys})"
  else "#{kind.capitalize}(:#{type}, #{value_keys})"
  end
end
MAP_STEP_MESSAGE =
lambda do |record|
  step = MAP_STEP_METHOD[record[:result]]

  method_name = record.dig(:and_then, :method_name)

  " * #{step} from method: #{method_name}".chomp("from method: ").chomp(" ")
end
MAP_IDS_WITH_MESSAGES =
lambda do |records|
  process_ids = []

  records.each_with_object([]) do |record, messages|
    current = record[:current]

    current_id = current[:id]

    unless process_ids.include?(current_id)
      process_ids << current_id

      id, name, desc = current.values_at(:id, :name, :desc)

      messages << [current_id, "##{id} #{name} - #{desc}".chomp("- ").chomp(" ")]
    end

    messages << [current_id, MAP_STEP_MESSAGE[record]]
  end
end

Class Method Summary collapse

Class Method Details

.map(event_logs) ⇒ Object



54
55
56
57
58
59
60
# File 'lib/solid/process/event_logs/basic_logger_listener.rb', line 54

def self.map(event_logs)
  ids_level_parent = event_logs.dig(:metadata, :ids, :level_parent)

  messages = MAP_IDS_WITH_MESSAGES[event_logs[:records]]

  messages.map { |(id, msg)| "#{"   " * ids_level_parent[id].first}#{msg}" }
end