Skip to content

Commit

Permalink
cleanup initialization process to better support Rails 3
Browse files Browse the repository at this point in the history
  • Loading branch information
briandoll committed Sep 16, 2010
1 parent 5bcaa2d commit 459eb19
Showing 1 changed file with 30 additions and 21 deletions.
51 changes: 30 additions & 21 deletions lib/rpm_contrib.rb
Original file line number Diff line number Diff line change
@@ -1,34 +1,43 @@

RPM_CONTRIB_LIB = File.dirname(__FILE__)

module RPMContrib
VERSION = File.read(RPM_CONTRIB_LIB+"/../CHANGELOG")[/Version ([\d\.]+)$/, 1]
end

# Perform any framework/dispatcher detection before loading the rpm
# gem.
def self.init_sequence
Proc.new do
# Tell the agent to load all the files in the
# rpm_contrib/instrumentation directory.
NewRelic::Agent.add_instrumentation(RPM_CONTRIB_LIB+"/rpm_contrib/instrumentation/**/*.rb")

# Load all the Sampler class definitions. These will register
# automatically with the agent.
Dir.glob(RPM_CONTRIB_LIB + "/rpm_contrib/samplers/**/*.rb") { |file| require file }
end
end

end

# Perform any framework/dispatcher detection before loading the rpm gem.
raise "The rpm_contrib gem must be loaded before the newrelic_rpm gem." if defined?(::NewRelic)

Dir.glob(RPM_CONTRIB_LIB + "/rpm_contrib/detection/**/*.rb") { |file| require file }

require 'newrelic_rpm'

init_sequence = Proc.new do

# Tell the agent to load all the files in the
# rpm_contrib/instrumentation directory.
NewRelic::Agent.add_instrumentation(RPM_CONTRIB_LIB+"/rpm_contrib/instrumentation/**/*.rb")

# Load all the Sampler class definitions. These will register
# automatically with the agent.
Dir.glob(RPM_CONTRIB_LIB + "/rpm_contrib/samplers/**/*.rb") { |file| require file }
end

if defined?(Rails.configuration)
Rails.configuration.after_initialize &init_sequence
if defined? Rails
# Rails 3.x+
if Rails.respond_to?(:version) && Rails.version =~ /^3/
module NewRelic
class Railtie < Rails::Railtie
initializer("rpm_contrib.start_plugin", &RPMContrib.init_sequence)
end
end
# Rails 2.x
elsif defined?(Rails) && Rails.respond_to?(:configuration)
Rails.configuration.after_initialize &RPMContrib.init_sequence
else
raise "The rpm_contrib gem supports Rails 2.2+ only."
end
else
init_sequence.call
end


RPMContrib.init_sequence.call
end

0 comments on commit 459eb19

Please sign in to comment.