activerecord-honeycomb 0.2.2 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 09fbe7feddc8d469cf58d65b096dfafedc9f2829c11ce22899bc4768c4df382f
|
4
|
+
data.tar.gz: 60012d9f52988eb0b5aaf479366b7a4e85a7cb85d05fb077eb5954bd389ce1eb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b8bf9645b2c1bf23184d6a957b639c794e8b6e871cf1a8ea334116d0c2bf36d145df13898c57a67ecdeb9aaf30ebd1be6a7f331df766144df73e685900df6984
|
7
|
+
data.tar.gz: 115d629a81825a47c9ce8da8d69d90245dbf0fe03a68d76b1bc01862d78b6b0ea68cf4360dfea675e035241c6d349df748e8a7ccd5a86c3085891b169c823d38
|
@@ -2,15 +2,33 @@ require 'active_record'
|
|
2
2
|
|
3
3
|
module ActiveRecord
|
4
4
|
module Honeycomb
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
5
|
+
class << self
|
6
|
+
def munge_config(config, client: nil, logger: nil)
|
7
|
+
config = resolve_config(config)
|
8
|
+
|
9
|
+
munged = config.merge(
|
10
|
+
'adapter' => 'honeycomb',
|
11
|
+
'real_adapter' => config.fetch('adapter'),
|
12
|
+
)
|
13
|
+
munged['honeycomb_client'] = client if client
|
14
|
+
munged['honeycomb_logger'] = logger if logger
|
15
|
+
logger.debug "#{self.name}: injected HoneycombAdapter config, original adapter was #{munged['real_adapter'].inspect}" if logger
|
16
|
+
munged
|
17
|
+
end
|
18
|
+
|
19
|
+
def resolve_config(config)
|
20
|
+
# ActiveRecord allows `config` to be a hash, an URL or a Symbol (the
|
21
|
+
# latter representing a key into ActiveRecord::Base.configurations,
|
22
|
+
# initialized elsewhere) - or even `nil` (in which case it checks the
|
23
|
+
# RAILS_ENV global and then falls back to the Symbol path). Rather than
|
24
|
+
# handle this mess, we use the same mechanism as
|
25
|
+
# ActiveRecord::Base.establish_connection to resolve it into a hash so
|
26
|
+
# we can munge it: see
|
27
|
+
# https://github.com/rails/rails/blob/9700dac/activerecord/lib/active_record/connection_handling.rb#L56-L57
|
28
|
+
|
29
|
+
resolver = ::ActiveRecord::ConnectionAdapters::ConnectionSpecification::Resolver.new(::ActiveRecord::Base.configurations)
|
30
|
+
resolver.resolve(config)
|
31
|
+
end
|
14
32
|
end
|
15
33
|
end
|
16
34
|
end
|
@@ -16,9 +16,9 @@ module ActiveRecord
|
|
16
16
|
require 'activerecord-honeycomb'
|
17
17
|
|
18
18
|
ActiveRecord::Base.extend(Module.new do
|
19
|
-
define_method :establish_connection do |config
|
19
|
+
define_method :establish_connection do |config=nil|
|
20
20
|
munged_config = ActiveRecord::Honeycomb.munge_config(config, client: honeycomb_client, logger: logger)
|
21
|
-
super(munged_config
|
21
|
+
super(munged_config)
|
22
22
|
end
|
23
23
|
end)
|
24
24
|
end
|