Sha256: 1b482dd63ab74ed3473006c20aaa409648c4f3e12dc876162eb3d5aa25665020

Contents?: true

Size: 1.55 KB

Versions: 13

Compression:

Stored size: 1.55 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?
            desc = "Available?: #{self.class.available?}"
            desc += ", Loaded? #{self.class.loaded?}"
            desc += ", Compatible? #{self.class.compatible?}"
            desc += ", Patchable? #{self.class.patchable?}"

            Datadog.logger.warn("Unable to patch #{self.class.name} (#{desc})")
            return
          end

          patcher.patch
        end
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 2 rubygems

Version Path
ddtrace-0.44.0 lib/ddtrace/contrib/patchable.rb
ddtrace-0.43.0 lib/ddtrace/contrib/patchable.rb
ddtrace-0.42.0 lib/ddtrace/contrib/patchable.rb
ddtrace-0.41.0 lib/ddtrace/contrib/patchable.rb
ls-trace-0.2.0 lib/ddtrace/contrib/patchable.rb
ddtrace-0.40.0 lib/ddtrace/contrib/patchable.rb
ddtrace-0.39.0 lib/ddtrace/contrib/patchable.rb
ddtrace-0.38.0 lib/ddtrace/contrib/patchable.rb
ddtrace-0.37.0 lib/ddtrace/contrib/patchable.rb
ddtrace-0.36.0 lib/ddtrace/contrib/patchable.rb
ddtrace-0.35.2 lib/ddtrace/contrib/patchable.rb
ddtrace-0.35.1 lib/ddtrace/contrib/patchable.rb
ddtrace-0.35.0 lib/ddtrace/contrib/patchable.rb