lib/hanami/providers/db/config.rb in hanami-2.2.0.beta1 vs lib/hanami/providers/db/config.rb in hanami-2.2.0.beta2
- old
+ new
@@ -2,18 +2,26 @@
require "dry/core"
module Hanami
module Providers
- class DB < Dry::System::Provider::Source
+ class DB < Hanami::Provider::Source
# @api public
# @since 2.2.0
class Config < Dry::Configurable::Config
include Dry::Core::Constants
# @api public
# @since 2.2.0
+ def gateway(key)
+ gateway = (gateways[key] ||= Gateway.new)
+ yield gateway if block_given?
+ gateway
+ end
+
+ # @api public
+ # @since 2.2.0
def adapter_name
self[:adapter]
end
# @api public
@@ -28,37 +36,25 @@
# @api public
# @since 2.2.0
def any_adapter
adapter = (adapters[nil] ||= Adapter.new)
- yield adapter if block_given?
+ yield adapter if block_given?
adapter
end
# @api private
- # @since 2.2.0
- def gateway_cache_keys
- adapters[adapter_name].gateway_cache_keys
- end
-
- # @api private
- # @since 2.2.0
- def gateway_options
- adapters[adapter_name].gateway_options
- end
-
- # @api public
- # @since 2.2.0
def each_plugin
+ return to_enum(__method__) unless block_given?
+
universal_plugins = adapters[nil].plugins
- adapter_plugins = adapters[adapter_name].plugins
- plugins = universal_plugins + adapter_plugins
+ gateways.values.group_by(&:adapter_name).each do |adapter_name, adapter_gateways|
+ per_adapter_plugins = adapter_gateways.map { _1.adapter.plugins }.flatten(1)
- return to_enum(__method__) unless block_given?
-
- plugins.each do |plugin_spec, config_block|
- yield plugin_spec, config_block
+ (universal_plugins + per_adapter_plugins).uniq.each do |plugin_spec, config_block|
+ yield adapter_name, plugin_spec, config_block
+ end
end
end
end
end
end