Class: ROM::Configuration

Inherits:
Object
  • Object
show all
Extended by:
Forwardable, Notifications
Includes:
ConfigurationDSL
Defined in:
lib/rom/configuration.rb

Constant Summary collapse

NoDefaultAdapterError =
::Class.new(::StandardError)

Constants included from Notifications

Notifications::LISTENERS_HASH

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Notifications

event_bus, events, listeners, register_event

Methods included from Notifications::Publisher

#subscribe, #trigger

Methods included from ConfigurationDSL

#commands, #mappers, #plugin, #plugin_registry, #relation

Constructor Details

#initialize(*args) {|_self| ... } ⇒ Configuration

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Initialize a new configuration

Yields:

  • (_self)

Yield Parameters:

See Also:



53
54
55
56
57
58
59
# File 'lib/rom/configuration.rb', line 53

def initialize(*args, &)
  @environment = Environment.new(*args)
  @notifications = Notifications.event_bus(:configuration)
  @setup = Setup.new(notifications)

  yield self if block_given?
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name) ⇒ Gateway (private)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns gateway if method is a name of a registered gateway

Returns:



130
# File 'lib/rom/configuration.rb', line 130

def method_missing(name, ...) = gateways.fetch(name) { super }

Instance Attribute Details

#environmentObject (readonly)

Returns the value of attribute environment.



29
30
31
# File 'lib/rom/configuration.rb', line 29

def environment
  @environment
end

#notificationsObject (readonly)

Returns the value of attribute notifications.



37
38
39
# File 'lib/rom/configuration.rb', line 37

def notifications
  @notifications
end

#setupObject (readonly)

Returns the value of attribute setup.



33
34
35
# File 'lib/rom/configuration.rb', line 33

def setup
  @setup
end

Instance Method Details

#[](name) ⇒ Gateway

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Return gateway identified by name

Returns:



86
# File 'lib/rom/configuration.rb', line 86

def [](name) = gateways.fetch(name)

#adapter_for_gateway(gateway) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



99
100
101
102
103
# File 'lib/rom/configuration.rb', line 99

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_adapterObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



116
117
118
# File 'lib/rom/configuration.rb', line 116

def default_adapter
  @default_adapter ||= adapter_for_gateway(default_gateway) || ROM.adapters.keys.first
end

#default_gatewayObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



94
95
96
# File 'lib/rom/configuration.rb', line 94

def default_gateway
  @default_gateway ||= gateways[:default]
end

#relation_classes(gateway = nil) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



106
107
108
109
110
111
112
113
# File 'lib/rom/configuration.rb', line 106

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) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Hook for respond_to? used internally

Returns:

  • (Boolean)


91
# File 'lib/rom/configuration.rb', line 91

def respond_to?(name, ...) = gateways.key?(name) || super

#use(plugin, options = {}) ⇒ Configuration

Apply a plugin to the configuration

Parameters:

  • plugin (Mixed)

    The plugin identifier, usually a Symbol

  • options (Hash) (defaults to: {})

    Plugin options

Returns:



69
70
71
72
73
74
75
76
77
78
79
# File 'lib/rom/configuration.rb', line 69

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