Sha256: 7bcdaa3c13bb9b9ba9ba7d427aeb12c45c62bf65513ab4bfd6861080766b60b2

Contents?: true

Size: 1.94 KB

Versions: 1

Compression:

Stored size: 1.94 KB

Contents

# frozen_string_literal: true

# File: to-trace.rb

require_relative 'all-notifications'

module Macros4Cuke # Module used as a namespace
# Namespace for all formatters of MacroCollection and MacroStep objects
module Formatter
  # A macro-step formatter that outputs in the given IO the formatting events.
  # Can be useful in tracing the visit sequence inside
  # a given macro-step collection.
  class ToTrace
    # The IO where the formatter's output will be written to.
    attr_reader(:io)


    def initialize(anIO)
      @io = anIO
    end

    # Tell which notifications the formatter subscribes to.
    def implements()
      return Formatter::AllNotifications
    end

    def on_collection(aLevel, _)
      trace_event(aLevel, __method__)
    end

    def on_collection_end(aLevel)
      trace_event(aLevel, __method__)
    end

    def on_step(aLevel, _)
      trace_event(aLevel, __method__)
    end

    def on_step_end(aLevel)
      trace_event(aLevel, __method__)
    end

    def on_phrase(aLevel, _, _)
      trace_event(aLevel, __method__)
    end

    def on_renderer(aLevel, _)
      trace_event(aLevel, __method__)
    end

    def on_renderer_end(aLevel)
      trace_event(aLevel, __method__)
    end

    def on_source(aLevel, _)
      trace_event(aLevel, __method__)
    end

    def on_static_text(aLevel, _)
      trace_event(aLevel, __method__)
    end

    def on_comment(aLevel, _)
      trace_event(aLevel, __method__)
    end

    def on_eol(aLevel)
      trace_event(aLevel, __method__)
    end

    def on_placeholder(aLevel, _)
      trace_event(aLevel, __method__)
    end

    def on_section(aLevel, _)
      trace_event(aLevel, __method__)
    end

    def on_section_end(aLevel)
      trace_event(aLevel, __method__)
    end

    private

    def indentation(aLevel)
      return '  ' * aLevel
    end

    def trace_event(aLevel, anEvent)
      io.puts "#{indentation(aLevel)}#{anEvent}"
    end
  end # class
end # module
end # module

# End of file

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
macros4cuke-0.5.17 lib/macros4cuke/formatter/to-trace.rb