Module: NewRelic::LanguageSupport

Extended by:
LanguageSupport
Included in:
LanguageSupport
Defined in:
lib/new_relic/language_support.rb

Constant Summary collapse

@@forkable =
nil

Instance Method Summary collapse

Instance Method Details

#bundled_gem?(gem_name) ⇒ Boolean



59
60
61
62
63
64
65
66
# File 'lib/new_relic/language_support.rb', line 59

def bundled_gem?(gem_name)
  return false unless defined?(Bundler)

  NewRelic::Helper.rubygems_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

#camelize(string) ⇒ Object



45
46
47
48
# File 'lib/new_relic/language_support.rb', line 45

def camelize(string)
  camelized = string.downcase
  camelized.split(/\-|\_/).map(&:capitalize).join
end

#camelize_with_first_letter_downcased(string) ⇒ Object



50
51
52
53
# File 'lib/new_relic/language_support.rb', line 50

def camelize_with_first_letter_downcased(string)
  camelized = camelize(string)
  camelized[0].downcase.concat(camelized[1..-1])
end

#can_fork?Boolean



10
11
12
13
14
15
# File 'lib/new_relic/language_support.rb', line 10

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

#constantize(const_name) ⇒ Object



38
39
40
41
42
43
# File 'lib/new_relic/language_support.rb', line 38

def constantize(const_name)
  return if const_name.nil?

  Object.const_get(const_name)
rescue NameError
end

#gc_profiler_enabled?Boolean



21
22
23
# File 'lib/new_relic/language_support.rb', line 21

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

#gc_profiler_usable?Boolean



17
18
19
# File 'lib/new_relic/language_support.rb', line 17

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

#jruby?Boolean



34
35
36
# File 'lib/new_relic/language_support.rb', line 34

def jruby?
  RUBY_ENGINE == 'jruby'
end

#object_space_usable?Boolean



25
26
27
28
29
30
31
32
# File 'lib/new_relic/language_support.rb', line 25

def object_space_usable?
  if jruby?
    require 'jruby'
    JRuby.runtime.is_object_space_enabled
  else
    defined?(::ObjectSpace)
  end
end

#snakeize(string) ⇒ Object



55
56
57
# File 'lib/new_relic/language_support.rb', line 55

def snakeize(string)
  string.gsub(/(.)([A-Z])/, '\1_\2').downcase
end