Sha256: f0b96b384f0c4d187e4fe151ee7b1a5d8b590538165bc196a4fe1c693b784662

Contents?: true

Size: 1.77 KB

Versions: 30

Compression:

Stored size: 1.77 KB

Contents

# encoding: utf-8
# This file is distributed under New Relic's license terms.
# See https://github.com/newrelic/rpm/blob/master/LICENSE for complete details.

module NewRelic
  module LanguageSupport
    extend self

    @@forkable = nil
    def can_fork?
      # this is expensive to check, so we should only check once
      return @@forkable if @@forkable != nil
      @@forkable = Process.respond_to?(:fork)
    end

    def gc_profiler_usable?
      defined?(::GC::Profiler) && !jruby?
    end

    def gc_profiler_enabled?
      gc_profiler_usable? && ::GC::Profiler.enabled? && !::NewRelic::Agent.config[:disable_gc_profiler]
    end

    def object_space_usable?
      if defined?(::JRuby) && JRuby.respond_to?(:runtime)
        JRuby.runtime.is_object_space_enabled
      else
        defined?(::ObjectSpace)
      end
    end

    def jruby?
      RUBY_ENGINE == 'jruby'
    end

    def constantize(const_name)
      const_name.to_s.sub(/\A::/,'').split('::').inject(Object) do |namespace, name|
        begin
          result = namespace.const_get(name)

          # const_get looks up the inheritence chain, so if it's a class
          # in the constant make sure we found the one in our namespace.
          #
          # Can't help if the constant isn't a class...
          if result.is_a?(Module)
            expected_name = "#{namespace}::#{name}".gsub(/^Object::/, "")
            return unless expected_name == result.to_s
          end

          result
        rescue NameError
          nil
        end
      end
    end

    def bundled_gem?(gem_name)
      defined?(Bundler) && Bundler.rubygems.all_specs.map(&:name).include?(gem_name)
    rescue => e
      ::NewRelic::Agent.logger.info("Could not determine if third party #{gem_name} gem is installed", e)
      false
    end
  end
end

Version data entries

30 entries across 30 versions & 1 rubygems

Version Path
newrelic_rpm-6.11.0.365 lib/new_relic/language_support.rb
newrelic_rpm-6.10.0.364 lib/new_relic/language_support.rb
newrelic_rpm-6.9.0.363 lib/new_relic/language_support.rb
newrelic_rpm-6.8.0.360 lib/new_relic/language_support.rb
newrelic_rpm-6.7.0.359 lib/new_relic/language_support.rb
newrelic_rpm-6.6.0.358 lib/new_relic/language_support.rb
newrelic_rpm-6.5.0.357 lib/new_relic/language_support.rb
newrelic_rpm-6.4.0.356 lib/new_relic/language_support.rb
newrelic_rpm-6.3.0.355 lib/new_relic/language_support.rb
newrelic_rpm-6.2.0.354 lib/new_relic/language_support.rb
newrelic_rpm-6.1.0.352 lib/new_relic/language_support.rb
newrelic_rpm-6.0.0.351 lib/new_relic/language_support.rb
newrelic_rpm-5.7.0.350 lib/new_relic/language_support.rb
newrelic_rpm-5.6.0.349 lib/new_relic/language_support.rb
newrelic_rpm-5.5.0.348 lib/new_relic/language_support.rb
newrelic_rpm-5.4.0.347 lib/new_relic/language_support.rb
newrelic_rpm-5.3.0.346 lib/new_relic/language_support.rb
newrelic_rpm-5.2.0.345 lib/new_relic/language_support.rb
newrelic_rpm-5.1.0.344 lib/new_relic/language_support.rb
newrelic_rpm-5.0.0.342 lib/new_relic/language_support.rb