class ROM::Environment
Core
gateway configuration interface
@api private
Attributes
gateways[R]
gateways_map[R]
Public Class Methods
new(*args)
click to toggle source
@api private
# File lib/rom/environment.rb, line 16 def initialize(*args) @gateways = {} @gateways_map = {} configure_gateways(*args) unless args.empty? end
Private Instance Methods
configure_gateways(*args)
click to toggle source
@api private
# File lib/rom/environment.rb, line 26 def configure_gateways(*args) normalized_gateway_args = normalize_gateway_args(*args) normalized_gateways = normalize_gateways(normalized_gateway_args) @gateways, @gateways_map = normalized_gateways.values_at(:gateways, :map) normalized_gateway_args.each_with_object(config) do |(name, gateway_config), config| options = gateway_config.is_a?(Array) && gateway_config.last load_config(config.gateways[name], options) if options.is_a?(Hash) end end
load_config(config, hash)
click to toggle source
@api private
# File lib/rom/environment.rb, line 65 def load_config(config, hash) hash.each do |key, value| if value.is_a?(Hash) load_config(config[key], value) else config.send("#{key}=", value) end end end
normalize_gateway_args(*args)
click to toggle source
@api private
# File lib/rom/environment.rb, line 39 def normalize_gateway_args(*args) args.first.is_a?(Hash) ? args.first : { default: args } end
normalize_gateways(gateways_config)
click to toggle source
Build gateways using the setup interface
@api private
# File lib/rom/environment.rb, line 46 def normalize_gateways(gateways_config) gateways_config.each_with_object(map: {}, gateways: {}) do |(name, spec), hash| identifier, *args = Array(spec) if identifier.is_a?(Gateway) gateway = identifier elsif RUBY_VERSION >= "3.0" kwargs = args.last.is_a?(Hash) ? args.pop : {} gateway = Gateway.setup(identifier, *args.flatten, **kwargs) else gateway = Gateway.setup(identifier, *args.flatten) end hash[:map][gateway] = name hash[:gateways][name] = gateway end end