module ElasticAPM::Spies

def self.hook_into(name)

def self.hook_into(name)
  return unless (registration = require_hooks[name])
  return unless safe_defined?(registration.const_name)
  installed[registration.const_name] = registration
  registration.install
  registration.require_paths.each do |path|
    require_hooks.delete path
  end
end

def self.installed

def self.installed
  @installed ||= {}
end

def self.register(*args)

def self.register(*args)
  registration = Registration.new(*args)
  if safe_defined?(registration.const_name)
    registration.install
    installed[registration.const_name] = registration
  else
    register_require_hook registration
  end
end

def self.register_require_hook(registration)

def self.register_require_hook(registration)
  registration.require_paths.each do |path|
    require_hooks[path] = registration
  end
end

def self.require_hooks

def self.require_hooks
  @require_hooks ||= {}
end

def self.safe_defined?(const_name)

def self.safe_defined?(const_name)
  Util::Inflector.safe_constantize(const_name)
end