Class: ROM::Configuration
- Inherits:
-
Object
- Object
- ROM::Configuration
- Extended by:
- Forwardable, Notifications
- Includes:
- ConfigurationDSL
- Defined in:
- lib/rom/configuration.rb
Constant Summary collapse
- NoDefaultAdapterError =
Class.new(StandardError)
Constants included from Notifications
Instance Attribute Summary collapse
-
#environment ⇒ Object
readonly
Returns the value of attribute environment.
-
#notifications ⇒ Object
readonly
Returns the value of attribute notifications.
-
#setup ⇒ Object
readonly
Returns the value of attribute setup.
Instance Method Summary collapse
-
#[](name) ⇒ Gateway
private
Return gateway identified by name.
- #adapter_for_gateway(gateway) ⇒ Object private
- #default_adapter ⇒ Object private
- #default_gateway ⇒ Object private
-
#initialize(*args, &block) ⇒ Configuration
constructor
private
Initialize a new configuration.
- #relation_classes(gateway = nil) ⇒ Object private
-
#respond_to?(name, include_all = false) ⇒ Boolean
private
Hook for respond_to? used internally.
-
#use(plugin, options = {}) ⇒ Configuration
Apply a plugin to the configuration.
Methods included from Notifications
event_bus, events, listeners, register_event
Methods included from Notifications::Publisher
Methods included from ConfigurationDSL
#commands, #plugin, #plugin_registry, #relation
Constructor Details
#initialize(*args, &block) ⇒ 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
50 51 52 53 54 55 56 57 58 |
# File 'lib/rom/configuration.rb', line 50 def initialize(*args, &block) @environment = Environment.new(*args) @notifications = Notifications.event_bus(:configuration) @setup = Setup.new(notifications) use :mappers # enable mappers by default block.call(self) if block 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
130 131 132 |
# File 'lib/rom/configuration.rb', line 130 def method_missing(name, *) gateways.fetch(name) { super } end |
Instance Attribute Details
#environment ⇒ Object (readonly)
Returns the value of attribute environment.
27 28 29 |
# File 'lib/rom/configuration.rb', line 27 def environment @environment end |
#notifications ⇒ Object (readonly)
Returns the value of attribute notifications.
35 36 37 |
# File 'lib/rom/configuration.rb', line 35 def notifications @notifications end |
#setup ⇒ Object (readonly)
Returns the value of attribute setup.
31 32 33 |
# File 'lib/rom/configuration.rb', line 31 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
85 86 87 |
# File 'lib/rom/configuration.rb', line 85 def [](name) gateways.fetch(name) end |
#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.
102 103 104 105 106 |
# File 'lib/rom/configuration.rb', line 102 def adapter_for_gateway(gateway) ROM.adapters.select do |key, value| value.const_defined?(:Gateway) && gateway.kind_of?(value.const_get(:Gateway)) end.keys.first end |
#default_adapter ⇒ 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.
119 120 121 |
# File 'lib/rom/configuration.rb', line 119 def default_adapter @default_adapter ||= adapter_for_gateway(default_gateway) || ROM.adapters.keys.first end |
#default_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.
97 98 99 |
# File 'lib/rom/configuration.rb', line 97 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.
109 110 111 112 113 114 115 116 |
# 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) ⇒ 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
92 93 94 |
# File 'lib/rom/configuration.rb', line 92 def respond_to?(name, include_all = false) gateways.key?(name) || super end |
#use(plugin, options = {}) ⇒ Configuration
Apply a plugin to the configuration
68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/rom/configuration.rb', line 68 def use(plugin, = {}) 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, ) end self end |