Sha256: 224f18700cd5bb53deb8be0b2063e653d3a1a90dbd9a532f45e9c8956de0fa82

Contents?: true

Size: 1.47 KB

Versions: 1

Compression:

Stored size: 1.47 KB

Contents

# frozen_string_literal: false

module Carioca
  module Services
    class Debugger
      def self.get(service:, trace: Carioca::Registry.config.debugger_tracer)
        ProxyDebug.new service:, trace:
      end
    end

    class ProxyDebug
      def initialize(service:, trace:)
        registry = Carioca::Registry.get
        @service = registry.get_service name: service
        @tracers = %i[output logger]
        raise "Debugger :trace is not valid : #{trace}, must be in : #{@tracers}" unless @tracers.include? trace

        @tracer = registry.get_service name: trace
        @tracer_type = trace
      end

      def method_missing(methodname, *args, **keywords, &)
        trace message: "BEGIN CALL for service #{@service} "
        trace message: "Method called: #{methodname} "
        trace message: "args : #{args.join ' '}"
        trace message: "keywords : #{keywords}"
        if block_given?
          trace message: 'block given'
          a = @service.send(methodname, *args, **keywords, &)
        else
          a = @service.send(methodname, *args, **keywords)
        end
        trace message: "=> method returned: #{a} "
        trace message: 'END CALL'

        a
      end

      def trace(message:)
        if @tracer_type == :output
          save = @tracer.mode
          @tracer.mode = :mono
          @tracer.debug message
          @tracer.mode = save
        else
          @tracer.debug('Carioca->ProxyDebug') { message }
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
carioca-2.1.5 lib/carioca/services/debug.rb