class ROM::Configuration

Constants

NoDefaultAdapterError

Attributes

environment[R]

@!attribute [r] environment

@return [Environment] Environment object with gateways
notifications[R]

@!attribute [r] notifications

@return [Notifications] Notification bus instance
setup[R]

@!attribute [r] setup

@return [Setup] Setup object which collects component classes and plugins

Public Class Methods

new(*args, &block) click to toggle source

Initialize a new configuration

@see Environment#initialize

@return [Configuration]

@api private

# File lib/rom/configuration.rb, line 52
def initialize(*args, &block)
  @environment = Environment.new(*args)
  @notifications = Notifications.event_bus(:configuration)
  @setup = Setup.new(notifications)

  block&.call(self)
end

Public Instance Methods

[](name) click to toggle source

Return gateway identified by name

@return [Gateway]

@api private

# File lib/rom/configuration.rb, line 85
def [](name)
  gateways.fetch(name)
end
adapter_for_gateway(gateway) click to toggle source

@api private

# File lib/rom/configuration.rb, line 102
def adapter_for_gateway(gateway)
  ROM.adapters.select do |_key, value|
    value.const_defined?(:Gateway) && gateway.is_a?(value.const_get(:Gateway))
  end.keys.first
end
default_adapter() click to toggle source

@api private

# File lib/rom/configuration.rb, line 119
def default_adapter
  @default_adapter ||= adapter_for_gateway(default_gateway) || ROM.adapters.keys.first
end
default_gateway() click to toggle source

@api private

# File lib/rom/configuration.rb, line 97
def default_gateway
  @default_gateway ||= gateways[:default]
end
relation_classes(gateway = nil) click to toggle source

@api private

# File lib/rom/configuration.rb, line 109
def relation_classes(gateway = nil)
  if gateway
    gw_name = gateway.is_a?(Symbol) ? gateway : gateways_map[gateway]
    setup.relation_classes.select { |rel| rel.gateway == gw_name }
  else
    setup.relation_classes
  end
end
respond_to?(name, include_all = false) click to toggle source

Hook for respond_to? used internally

@api private

Calls superclass method
# File lib/rom/configuration.rb, line 92
def respond_to?(name, include_all = false)
  gateways.key?(name) || super
end
use(plugin, options = {}) click to toggle source

Apply a plugin to the configuration

@param [Mixed] plugin The plugin identifier, usually a Symbol @param [Hash] options Plugin options

@return [Configuration]

@api public

# File lib/rom/configuration.rb, line 68
def use(plugin, options = {})
  if plugin.is_a?(Array)
    plugin.each { |p| use(p) }
  elsif plugin.is_a?(Hash)
    plugin.to_a.each { |p| use(*p) }
  else
    ROM.plugin_registry[:configuration].fetch(plugin).apply_to(self, options)
  end

  self
end

Private Instance Methods

method_missing(name, *) click to toggle source

Returns gateway if method is a name of a registered gateway

@return [Gateway]

@api private

Calls superclass method
# File lib/rom/configuration.rb, line 130
def method_missing(name, *)
  gateways.fetch(name) { super }
end