Class: NewRelic::Agent::DatabaseAdapter

Inherits:
Object
  • Object
show all
Defined in:
lib/new_relic/agent/database_adapter.rb

Constant Summary collapse

VERSIONS =
{
  '6.1.0' => proc { ActiveRecord::Base.connection_db_config.configuration_hash[:adapter] },
  '4.0.0' => proc { ActiveRecord::Base.connection_config[:adapter] },
  '3.0.0' => proc { |env| ActiveRecord::Base.configurations[env]['adapter'] }
}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(env, version) ⇒ DatabaseAdapter

Returns a new instance of DatabaseAdapter.



22
23
24
25
# File 'lib/new_relic/agent/database_adapter.rb', line 22

def initialize(env, version)
  @env = env
  @version = Gem::Version.new(version)
end

Instance Attribute Details

#envObject (readonly)

Returns the value of attribute env.



20
21
22
# File 'lib/new_relic/agent/database_adapter.rb', line 20

def env
  @env
end

#versionObject (readonly)

Returns the value of attribute version.



20
21
22
# File 'lib/new_relic/agent/database_adapter.rb', line 20

def version
  @version
end

Class Method Details

.valueObject



14
15
16
17
18
# File 'lib/new_relic/agent/database_adapter.rb', line 14

def self.value
  return unless defined? ActiveRecord::Base

  new(::NewRelic::Control.instance.env, ActiveRecord::VERSION::STRING).value
end

Instance Method Details

#valueObject



27
28
29
30
31
32
# File 'lib/new_relic/agent/database_adapter.rb', line 27

def value
  match = VERSIONS.keys.find { |key| version >= Gem::Version.new(key) }
  return unless match

  VERSIONS[match].call(env)
end