activerecord-honeycomb 0.2.2 → 0.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1686f5b56b0a372f7af11190a4206f6aa69e2e88efc761306db4de3bc96340ca
4
- data.tar.gz: 14dcd90cb80a06bf4c4d8eb30ae8bb75af36bc5a92a2403cd05004bc9ea7b1d8
3
+ metadata.gz: 09fbe7feddc8d469cf58d65b096dfafedc9f2829c11ce22899bc4768c4df382f
4
+ data.tar.gz: 60012d9f52988eb0b5aaf479366b7a4e85a7cb85d05fb077eb5954bd389ce1eb
5
5
  SHA512:
6
- metadata.gz: 682f11006a356983eba992dd7fe89459f3765b4ec645732be97d20a252bf5ffd42ab7920dee3e9ecbbfebd1d9773106363608098313f7bf3d52e4c2afa2f5016
7
- data.tar.gz: 31a130980f993521081dc276e3d622bc9e62fddba25db982d1a53e231086aaafa1053b4c99aeef8e2ac30c73a2a0d1d160898b07eba77e7a53f1a3716e1cf4f4
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
- def self.munge_config(config, client: nil, logger: nil)
6
- munged = config.merge(
7
- 'adapter' => 'honeycomb',
8
- 'real_adapter' => config.fetch('adapter'),
9
- )
10
- munged['honeycomb_client'] = client if client
11
- munged['honeycomb_logger'] = logger if logger
12
- logger.debug "#{self.name}: injected HoneycombAdapter config, original adapter was #{munged['real_adapter'].inspect}" if logger
13
- munged
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
@@ -1,6 +1,6 @@
1
1
  module ActiveRecord
2
2
  module Honeycomb
3
3
  GEM_NAME = 'activerecord-honeycomb'
4
- VERSION = '0.2.2'
4
+ VERSION = '0.2.3'
5
5
  end
6
6
  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, *args|
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, *args)
21
+ super(munged_config)
22
22
  end
23
23
  end)
24
24
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord-honeycomb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sam Stokes