Sha256: 6ea788980e0aefafc27d451a8ce6a540ffb80b205033b26128bf966d0f7ccd78

Contents?: true

Size: 1.19 KB

Versions: 16

Compression:

Stored size: 1.19 KB

Contents

module Datadog
  # Defines some useful patching methods for integrations
  module Patcher
    def self.included(base)
      base.send(:extend, CommonMethods)
      base.send(:include, CommonMethods)
    end

    # Defines some common methods for patching, that can be used
    # at the instance, class, or module level.
    module CommonMethods
      def without_warnings
        # This is typically used when monkey patching functions such as
        # intialize, which Ruby advices you not to. Use cautiously.
        v = $VERBOSE
        $VERBOSE = nil
        begin
          yield
        ensure
          $VERBOSE = v
        end
      end

      def do_once(key = nil)
        # If already done, don't do again
        @done_once ||= {}
        return @done_once[key] if @done_once.key?(key)

        # Otherwise 'do'
        yield.tap do
          # Then add the key so we don't do again.
          @done_once[key] = true
        end
      end

      def done?(key)
        return false unless instance_variable_defined?(:@done_once)
        !@done_once.nil? && @done_once.key?(key)
      end
    end

    # Extend the common methods so they're available as a module function.
    extend(CommonMethods)
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
ddtrace-0.17.2 lib/ddtrace/patcher.rb
ddtrace-0.17.1 lib/ddtrace/patcher.rb
ddtrace-0.17.0 lib/ddtrace/patcher.rb
ddtrace-0.16.1 lib/ddtrace/patcher.rb
ddtrace-0.15.0.internaltracinfeature1 lib/ddtrace/patcher.rb
ddtrace-0.16.0 lib/ddtrace/patcher.rb
ddtrace-0.14.2.disableprotocolversion4 lib/ddtrace/patcher.rb
ddtrace-0.15.0 lib/ddtrace/patcher.rb
ddtrace-0.14.2.withoutpriorityparsing1 lib/ddtrace/patcher.rb
ddtrace-0.14.2 lib/ddtrace/patcher.rb
ddtrace-0.14.1 lib/ddtrace/patcher.rb
ddtrace-0.15.0.beta1 lib/ddtrace/patcher.rb
ddtrace-0.14.0 lib/ddtrace/patcher.rb
ddtrace-0.14.0.rc1 lib/ddtrace/patcher.rb
ddtrace-0.14.0.beta2 lib/ddtrace/patcher.rb
ddtrace-0.14.0.beta1 lib/ddtrace/patcher.rb