From 66bc23fe2efeb7503ce9643f9f1e0aaaa1ce6ee9 Mon Sep 17 00:00:00 2001 From: Manish Untwal Date: Wed, 24 Feb 2021 13:11:30 +0530 Subject: [PATCH] Make sure ArResolver works for other adapter with proxy --- .../extend/adapters/other_adapter_proxy.rb | 13 +++++++++++++ lib/fresh_connection/extend/ar_resolver.rb | 7 ++++++- 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 lib/fresh_connection/extend/adapters/other_adapter_proxy.rb diff --git a/lib/fresh_connection/extend/adapters/other_adapter_proxy.rb b/lib/fresh_connection/extend/adapters/other_adapter_proxy.rb new file mode 100644 index 0000000..342e9b1 --- /dev/null +++ b/lib/fresh_connection/extend/adapters/other_adapter_proxy.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +module FreshConnection + module Extend + module OtherAdapterProxy + private + + def __change_connection + yield + end + end + end +end diff --git a/lib/fresh_connection/extend/ar_resolver.rb b/lib/fresh_connection/extend/ar_resolver.rb index d4fee42..7d0b6f4 100644 --- a/lib/fresh_connection/extend/ar_resolver.rb +++ b/lib/fresh_connection/extend/ar_resolver.rb @@ -14,7 +14,12 @@ def spec(*args) require 'fresh_connection/extend/adapters/pg_adapter' __extend_adapter_by_fc(::ActiveRecord::ConnectionAdapters::PostgreSQLAdapter, PgAdapter) else - raise NotImplementedError, "This adapter('#{specification.config[:adapter]}') is not supported. If you specified the mysql or postgres adapter, it's probably a bug in FreshConnection. Please teach me (https://github.com/tsukasaoishi/fresh_connection/issues/new)" + require 'fresh_connection/extend/adapters/other_adapter_proxy' + base_adapter_name = "#{specification.config[:adapter].to_s}_adapter".camelize + __extend_adapter_by_fc( + "::ActiveRecord::ConnectionAdapters::#{base_adapter_name}".constantize, + OtherAdapterProxy + ) end specification