Class: ROM::Gateway Abstract
- Inherits:
-
Object
- Object
- ROM::Gateway
- Extended by:
- Dry::Core::ClassAttributes, Notifications::Listener
- Defined in:
- core/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.
-
.setup(gateway_or_scheme, *args) ⇒ Gateway
Set up a gateway.
-
.subscribe(event_id, query = EMPTY_HASH, &block) ⇒ Object
extended
from Notifications::Listener
Subscribe to events.
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.
-
#transaction(opts = EMPTY_HASH, &block) ⇒ Object
Runs a block inside a transaction.
-
#use_logger ⇒ Object
abstract
A generic interface for setting up a logger.
Instance Attribute Details
#connection ⇒ Object (readonly)
39 40 41 |
# File 'core/lib/rom/gateway.rb', line 39 def connection @connection end |
Class Method Details
.adapter ⇒ Symbol .gateway(adapter) ⇒ Object
Get or set gateway's adapter identifier
35 |
# File 'core/lib/rom/gateway.rb', line 35 defines :adapter |
.setup(type, *args) ⇒ Gateway .setup(gateway) ⇒ Gateway
Set up a gateway
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'core/lib/rom/gateway.rb', line 83 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.zero? klass.new else klass.new(*args) end else raise ArgumentError, "Can't accept arguments when passing an instance" unless args.empty? gateway_or_scheme end end |
.subscribe(event_id, query = EMPTY_HASH, &block) ⇒ Object Originally defined in module Notifications::Listener
Subscribe to events
Instance Method Details
#adapter ⇒ Symbol
Returns the adapter, defined for the class
131 132 133 134 135 136 |
# File 'core/lib/rom/gateway.rb', line 131 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
164 165 166 |
# File 'core/lib/rom/gateway.rb', line 164 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.
157 158 159 |
# File 'core/lib/rom/gateway.rb', line 157 def logger # noop end |
#transaction(opts = EMPTY_HASH, &block) ⇒ Object
Runs a block inside a transaction. The underlying transaction engine is adapter-specific
177 178 179 |
# File 'core/lib/rom/gateway.rb', line 177 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
145 146 147 |
# File 'core/lib/rom/gateway.rb', line 145 def use_logger(*) # noop end |