Class: NRBundlerPatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/boot/strap.rb

Constant Summary collapse

BUNDLER =
'bundler'
RUBYOPT =
'RUBYOPT'

Class Method Summary collapse

Class Method Details

.check_for_bundlerObject



83
84
85
86
87
88
89
90
91
# File 'lib/boot/strap.rb', line 83

def self.check_for_bundler
  require_bundler

  raise 'Required Ruby Bundler class Bundler::Runtime not defined!' unless defined?(Bundler::Runtime)

  unless Bundler::Runtime.method_defined?(:require)
    raise "The active Ruby Bundler instance doesn't offer Bundler::Runtime#require"
  end
end

.check_for_requireObject



73
74
75
# File 'lib/boot/strap.rb', line 73

def self.check_for_require
  raise "#{__FILE__} is meant to be required, not invoked directly" if $PROGRAM_NAME == __FILE__
end

.check_for_rubyoptObject



77
78
79
80
81
# File 'lib/boot/strap.rb', line 77

def self.check_for_rubyopt
  unless ENV[RUBYOPT].to_s.match?("-r #{__FILE__.rpartition('.').first}")
    raise "#{__FILE__} is meant to be required via the RUBYOPT env var"
  end
end

.patchObject



62
63
64
65
66
67
68
69
# File 'lib/boot/strap.rb', line 62

def self.patch
  check_for_require
  check_for_rubyopt
  check_for_bundler
  Bundler::Runtime.prepend(NRBundlerPatch)
rescue StandardError => e
  Kernel.warn "New Relic entrypoint at #{__FILE__} encountered an issue:\n  #{e.message}"
end

.require_bundlerObject



93
94
95
96
97
# File 'lib/boot/strap.rb', line 93

def self.require_bundler
  require BUNDLER
rescue LoadError => e
  raise "Required Ruby library '#{BUNDLER}' could not be required - #{e}"
end