Sha256: 028622eeb7cfde7f2e07b9392f78774eb17998ca9ce886c20ac71772630df069

Contents?: true

Size: 1.28 KB

Versions: 1

Compression:

Stored size: 1.28 KB

Contents

module Vedeu
  class Trace

    # :nocov:
    # @param options [Hash]
    # @return []
    def self.call(options = {})
      new(options).trace
    end

    # @param options [Hash]
    # @return [Trace]
    def initialize(options = {})
      @options = options
    end

    # @return []
    def trace
      set_trace_func proc { |event, file, line, id, binding, classname|
        if event == watched && classname.to_s.match(klass)
          Vedeu.log(sprintf(" %s %-35s #%s", event, classname, id))
          # binding.eval('local_variables').each do |var|
          #   print("#{var.to_s} = #{binding.local_variable_get(var).inspect}\n")
          # end
        end
      }
    end

    private

    # @api private
    # @return []
    def watched
      options[:event]
    end

    # @api private
    # @return []
    def klass
      options[:klass]
    end

    # @api private
    # @return [Hash]
    def options
      defaults.merge!(@options)
    end

    # @api private
    # @return [Hash]
    def defaults
      {
        event: 'call',
        klass: /^Vedeu::(?!.*Log|Interface|Line|Stream|Style|Colour|Geometry|Terminal|Esc|ColourTranslator).*/
      }
    end

    # everything except Interface, Geometry and Terminal
    # klass: /^Vedeu::(?!.*Interface|Geometry|Terminal).*/
  end
  # :nocov:
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
vedeu-0.1.18 lib/vedeu/support/trace.rb