Sha256: 612c5decb26099e9f00a5ce50731e88844cf0b75766082b2ec75705e38abf651

Contents?: true

Size: 1.64 KB

Versions: 12

Compression:

Stored size: 1.64 KB

Contents

# frozen_string_literal: true

def ruby2_keywords(*); end unless respond_to?(:ruby2_keywords, true)

module AppMap
  class Hook
    # Delegation methods for Ruby 2.
    # cf. https://eregon.me/blog/2019/11/10/the-delegation-challenge-of-ruby27.html
    class Method
      ruby2_keywords def call(receiver, *args, &block)
        return do_call(receiver, *args, &block) unless trace?

        call_event = with_disabled_hook { before_hook receiver, *args }
        trace_call call_event, receiver, *args, &block
      end

      protected

      def before_hook(receiver, *args)
        call_event = handle_call(receiver, args)
        if call_event
          AppMap.tracing.record_event \
            call_event,
            package: hook_package,
            defined_class: defined_class,
            method: hook_method
        end
        call_event
      end

      ruby2_keywords def do_call(receiver, *args, &block)
        hook_method.bind(receiver).call(*args, &block)
      end

      ruby2_keywords def trace_call(call_event, receiver, *args, &block)
        start_time = gettime
        begin
          return_value = do_call(receiver, *args, &block)
        rescue # rubocop:disable Style/RescueStandardError
          exception = $ERROR_INFO
          raise
        ensure
          with_disabled_hook { after_hook receiver, call_event, gettime - start_time, return_value, exception } \
            if call_event
        end
      end

      def hook_method_def
        this = self
        proc { |*args, &block| this.call self, *args, &block }.tap do |hook|
          hook.ruby2_keywords if hook.respond_to? :ruby2_keywords
        end
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
appmap-0.83.2 lib/appmap/hook/method/ruby2.rb
appmap-0.83.1 lib/appmap/hook/method/ruby2.rb
appmap-0.83.0 lib/appmap/hook/method/ruby2.rb
appmap-0.82.0 lib/appmap/hook/method/ruby2.rb
appmap-0.81.1 lib/appmap/hook/method/ruby2.rb
appmap-0.81.0 lib/appmap/hook/method/ruby2.rb
appmap-0.80.2 lib/appmap/hook/method/ruby2.rb
appmap-0.80.1 lib/appmap/hook/method/ruby2.rb
appmap-0.80.0 lib/appmap/hook/method/ruby2.rb
appmap-0.79.0 lib/appmap/hook/method/ruby2.rb
appmap-0.78.0 lib/appmap/hook/method/ruby2.rb
appmap-0.77.4 lib/appmap/hook/method/ruby2.rb