Class: ROM::Gateway Abstract
- Inherits:
-
Object
- Object
- ROM::Gateway
- Extended by:
- Dry::Core::ClassAttributes, Notifications::Listener
- Defined in:
- lib/rom/gateway.rb
Overview
Abstract gateway class
Every adapter needs to inherit from this class and implement required interface
Direct Known Subclasses
Instance Attribute Summary collapse
- #connection ⇒ Object readonly
Class Method Summary collapse
-
.adapter ⇒ Object
Get or set gateway’s adapter identifier.
-
.class_from_symbol(type) ⇒ Class
private
Get gateway subclass for a specific adapter.
-
.mapper_compiler ⇒ Object
Get or set gateway-specific mapper compiler class.
-
.setup(gateway_or_scheme, *args) ⇒ Gateway
Set up a gateway.
Instance Method Summary collapse
-
#adapter ⇒ Symbol
Returns the adapter, defined for the class.
-
#disconnect ⇒ Object
Disconnect is optional and it’s a no-op by default.
-
#logger ⇒ NilClass
A generic interface for returning default logger.
-
#mapper_compiler ⇒ Class
private
Return configured mapper compiler class.
-
#transaction(opts = EMPTY_HASH, &block) ⇒ Object
Runs a block inside a transaction.
-
#use_logger ⇒ Object
abstract
A generic interface for setting up a logger.
Methods included from Notifications::Listener
Instance Attribute Details
#connection ⇒ Object (readonly)
53 54 55 |
# File 'lib/rom/gateway.rb', line 53 def connection @connection end |
Class Method Details
.adapter ⇒ Symbol .gateway(adapter) ⇒ Object
Get or set gateway’s adapter identifier
33 |
# File 'lib/rom/gateway.rb', line 33 defines :adapter |
.class_from_symbol(type) ⇒ Class
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.
Get gateway subclass for a specific adapter
128 129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/rom/gateway.rb', line 128 def self.class_from_symbol(type) adapter = ROM.adapters.fetch(type) { begin require "rom/#{type}" rescue LoadError raise AdapterLoadError, "Failed to load adapter rom/#{type}" end ROM.adapters.fetch(type) } adapter.const_get(:Gateway) end |
.mapper_compiler ⇒ Class .mapper_compiler(klass) ⇒ Object
Get or set gateway-specific mapper compiler class
49 |
# File 'lib/rom/gateway.rb', line 49 defines :mapper_compiler |
.setup(type, *args) ⇒ Gateway .setup(gateway) ⇒ Gateway
Set up a gateway
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/rom/gateway.rb', line 97 def self.setup(gateway_or_scheme, *args) case gateway_or_scheme when String raise ArgumentError, <<-STRING.gsub(/^ {10}/, '') URIs without an explicit scheme are not supported anymore. See https://github.com/rom-rb/rom/blob/master/CHANGELOG.md STRING when Symbol klass = class_from_symbol(gateway_or_scheme) if klass.instance_method(:initialize).arity == 0 klass.new else klass.new(*args) end else if args.empty? gateway_or_scheme else raise ArgumentError, "Can't accept arguments when passing an instance" end end end |
Instance Method Details
#adapter ⇒ Symbol
Returns the adapter, defined for the class
147 148 149 150 151 152 |
# File 'lib/rom/gateway.rb', line 147 def adapter self.class.adapter || raise( MissingAdapterIdentifierError, "gateway class +#{self}+ is missing the adapter identifier" ) end |
#disconnect ⇒ Object
Disconnect is optional and it’s a no-op by default
180 181 182 |
# File 'lib/rom/gateway.rb', line 180 def disconnect # noop end |
#logger ⇒ NilClass
A generic interface for returning default logger
Adapters should implement this method as handling loggers is different across adapters. This is a no-op by default and returns nil.
173 174 175 |
# File 'lib/rom/gateway.rb', line 173 def logger # noop end |
#mapper_compiler ⇒ Class
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 configured mapper compiler class
202 203 204 |
# File 'lib/rom/gateway.rb', line 202 def mapper_compiler self.class.mapper_compiler end |
#transaction(opts = EMPTY_HASH, &block) ⇒ Object
Runs a block inside a transaction. The underlying transaction engine is adapter-specific
193 194 195 |
# File 'lib/rom/gateway.rb', line 193 def transaction(opts = EMPTY_HASH, &block) transaction_runner(opts).run(opts, &block) end |
#use_logger ⇒ Object
A generic interface for setting up a logger
This is not a required interface, it’s a no-op by default
161 162 163 |
# File 'lib/rom/gateway.rb', line 161 def use_logger(*) # noop end |