Sha256: f19413d4d8f2b36ff562d7744d13cd3800a505b7234e7a23192d9a8a35e26a62

Contents?: true

Size: 1.91 KB

Versions: 5

Compression:

Stored size: 1.91 KB

Contents

module Datadog
  module Contrib
    # Base provides features that are shared across all integrations
    module Patchable
      def self.included(base)
        base.send(:extend, ClassMethods)
        base.send(:include, InstanceMethods)
      end

      # Class methods for integrations
      module ClassMethods
        def version
          nil
        end

        # Is the target available? (e.g. gem installed?)
        def available?
          !version.nil?
        end

        # Is the target loaded into the application? (e.g. constants defined?)
        def loaded?
          true
        end

        # Is the loaded code compatible with this integration? (e.g. minimum version met?)
        def compatible?
          available? && Gem::Version.new(RUBY_VERSION) >= Gem::Version.new(VERSION::MINIMUM_RUBY_VERSION)
        end

        # Can the patch for this integration be applied?
        def patchable?
          available? && loaded? && compatible?
        end
      end

      # Instance methods for integrations
      module InstanceMethods
        def patcher
          nil
        end

        def patch
          if !self.class.patchable? || patcher.nil?
            return {
              name: self.class.name,
              available: self.class.available?,
              loaded: self.class.loaded?,
              compatible: self.class.compatible?,
              patchable: self.class.patchable?
            }
          end

          patcher.patch
          true
        end

        # Can the patch for this integration be applied automatically?
        # For example: test integrations should only be applied
        # by the user explicitly setting `c.use :rspec`
        # and rails sub-modules are auto-instrumented by enabling rails
        # so auto-instrumenting them on their own will cause changes in
        # service naming behavior
        def auto_instrument?
          true
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
ddtrace-0.49.0 lib/ddtrace/contrib/patchable.rb
ddtrace-0.48.0 lib/ddtrace/contrib/patchable.rb
ddtrace-0.47.0 lib/ddtrace/contrib/patchable.rb
ddtrace-0.46.0 lib/ddtrace/contrib/patchable.rb
ddtrace-0.45.0 lib/ddtrace/contrib/patchable.rb