Skip to content

Commit

Permalink
Fix the workaround in the presence of wrapper functions.
Browse files Browse the repository at this point in the history
  • Loading branch information
ioquatix committed Feb 28, 2018
1 parent d82d465 commit cb89c89
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 17 deletions.
35 changes: 19 additions & 16 deletions lib/active_record/configurations.rb
Expand Up @@ -18,11 +18,29 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.

require_relative "configurations/version"
require_relative 'configurations/version'

require 'build/environment'
require 'active_record'

module ActiveRecord
class Base
# This is a quick hack to work around https://github.com/rails/rails/pull/32135
def self.establish_connection(config = nil)
raise "Anonymous class is not allowed." unless name

config ||= DEFAULT_ENV.call.to_sym
spec_name = self == Base ? "primary" : name
self.connection_specification_name = spec_name

resolver = ConnectionAdapters::ConnectionSpecification::Resolver.new(self.configurations)
spec = resolver.resolve(config).symbolize_keys
spec[:name] = spec_name

connection_handler.establish_connection(spec)
end
end

module Configurations
def self.extended(child)
child.instance_variable_set(:@environments, {})
Expand Down Expand Up @@ -113,20 +131,5 @@ def configure(name, parent: :default, &block)

self.configurations[name.to_s] = configuration.stringify_keys
end

# This is a quick hack to work around https://github.com/rails/rails/pull/32135
def establish_connection(config = nil)
raise "Anonymous class is not allowed." unless name

config ||= DEFAULT_ENV.call.to_sym
spec_name = self == Base ? "primary" : name
self.connection_specification_name = spec_name

resolver = ConnectionAdapters::ConnectionSpecification::Resolver.new(self.configurations)
spec = resolver.resolve(config).symbolize_keys
spec[:name] = spec_name

connection_handler.establish_connection(spec)
end
end
end
2 changes: 1 addition & 1 deletion lib/active_record/configurations/version.rb
Expand Up @@ -20,6 +20,6 @@

module ActiveRecord
module Configurations
VERSION = "0.3.0"
VERSION = "0.4.0"
end
end

0 comments on commit cb89c89

Please sign in to comment.