Sha256: 30d94c3508c7bb83a979e8b8a75053b09a1bc404c29e841ae66673a0b37abc28

Contents?: true

Size: 1.91 KB

Versions: 5

Compression:

Stored size: 1.91 KB

Contents

# typed: false
module Datadog
  module Contrib
    # Base provides features that are shared across all integrations
    module Patchable
      def self.included(base)
        base.extend(ClassMethods)
        base.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.54.2 lib/ddtrace/contrib/patchable.rb
ddtrace-0.54.1 lib/ddtrace/contrib/patchable.rb
ddtrace-0.54.0 lib/ddtrace/contrib/patchable.rb
ddtrace-0.53.0 lib/ddtrace/contrib/patchable.rb
ddtrace-0.52.0 lib/ddtrace/contrib/patchable.rb