Sha256: bab6b4ab24d9f731cfc7c876acce5ce80506022187942daf42af5e4c6b48fa96

Contents?: true

Size: 1.06 KB

Versions: 50

Compression:

Stored size: 1.06 KB

Contents

require 'set'
require 'ddtrace/patcher'

module Datadog
  # Shorthands for wrapping methods
  module MethodWrapping
    include Datadog::Patcher

    def wrapped_methods
      @wrapped_methods ||= Set.new
    end

    # Adds method block directly to the object.
    # Block is evaluated in the context of the object.
    # Faster than #wrap_method!
    def override_method!(method_name, &block)
      return unless block_given?

      without_warnings do
        define_singleton_method(method_name, &block).tap do
          wrapped_methods.add(method_name)
        end
      end
    end

    # Adds method wrapper to the object.
    # Block is evaluated in the original context of the block.
    # Slower than #override_method!
    def wrap_method!(original_method, &block)
      return unless block_given?
      original_method = original_method.is_a?(Symbol) ? method(original_method) : original_method

      override_method!(original_method.name) do |*original_args, &original_block|
        block.call(original_method, *original_args, &original_block)
      end
    end
  end
end

Version data entries

50 entries across 50 versions & 2 rubygems

Version Path
ddtrace-0.45.0 lib/ddtrace/augmentation/method_wrapping.rb
ddtrace-0.44.0 lib/ddtrace/augmentation/method_wrapping.rb
ddtrace-0.43.0 lib/ddtrace/augmentation/method_wrapping.rb
ddtrace-0.42.0 lib/ddtrace/augmentation/method_wrapping.rb
ddtrace-0.41.0 lib/ddtrace/augmentation/method_wrapping.rb
ls-trace-0.2.0 lib/ddtrace/augmentation/method_wrapping.rb
ddtrace-0.40.0 lib/ddtrace/augmentation/method_wrapping.rb
ddtrace-0.39.0 lib/ddtrace/augmentation/method_wrapping.rb
ddtrace-0.38.0 lib/ddtrace/augmentation/method_wrapping.rb
ddtrace-0.37.0 lib/ddtrace/augmentation/method_wrapping.rb
ddtrace-0.36.0 lib/ddtrace/augmentation/method_wrapping.rb
ls-trace-0.1.2 lib/ddtrace/augmentation/method_wrapping.rb
ddtrace-0.35.2 lib/ddtrace/augmentation/method_wrapping.rb
ddtrace-0.35.1 lib/ddtrace/augmentation/method_wrapping.rb
ddtrace-0.35.0 lib/ddtrace/augmentation/method_wrapping.rb
ddtrace-0.34.2 lib/ddtrace/augmentation/method_wrapping.rb
ddtrace-0.34.1 lib/ddtrace/augmentation/method_wrapping.rb
ddtrace-0.34.0 lib/ddtrace/augmentation/method_wrapping.rb
ddtrace-0.33.1 lib/ddtrace/augmentation/method_wrapping.rb
ddtrace-0.33.0 lib/ddtrace/augmentation/method_wrapping.rb