Class: Importu::Backends
- Inherits:
-
Object
- Object
- Importu::Backends
- Defined in:
- lib/importu/backends.rb,
lib/importu/backends/middleware.rb
Overview
Registry for persistence backends.
Backends handle persisting imported records to a data store. The registry allows registering custom backends and auto-detecting which backend to use based on the model class.
Defined Under Namespace
Modules: Middleware Classes: ActiveRecord
Class Method Summary collapse
-
.middleware ⇒ Array<Class>
Returns the middleware classes applied to all backends.
-
.registry ⇒ Importu::Backends
Returns the global backend registry instance.
Instance Method Summary collapse
-
#from_config!(name:, model:) ⇒ Class
Resolves a backend class from importer configuration.
-
#initialize ⇒ Backends
constructor
private
Creates a new backend registry.
-
#lookup(name) ⇒ Class
Looks up a backend by name.
-
#names ⇒ Array<Symbol>
Returns all registered backend names.
-
#register(name, klass) ⇒ Class
Registers a backend class.
Constructor Details
#initialize ⇒ Backends
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.
Creates a new backend registry.
40 41 42 43 44 |
# File 'lib/importu/backends.rb', line 40 def initialize @registered = Hash.new do |_hash, key| raise Importu::BackendNotRegistered, key end end |
Class Method Details
.middleware ⇒ Array<Class>
Returns the middleware classes applied to all backends.
23 24 25 26 27 28 |
# File 'lib/importu/backends.rb', line 23 def self.middleware [ Importu::Backends::Middleware::EnforceAllowedActions, Importu::Backends::Middleware::DuplicateManagerProxy, ] end |
.registry ⇒ Importu::Backends
Returns the global backend registry instance.
33 34 35 |
# File 'lib/importu/backends.rb', line 33 def self.registry @registry ||= new end |
Instance Method Details
#from_config!(name:, model:) ⇒ Class
Resolves a backend class from importer configuration.
53 54 55 56 57 |
# File 'lib/importu/backends.rb', line 53 def from_config!(name:, model:, **) model = model.is_a?(String) ? self.class.const_get(model) : model # Support :auto as an explicit way to request auto-detection (same as nil) name && name != :auto ? lookup(name) : detect_from_model(model) end |
#lookup(name) ⇒ Class
Looks up a backend by name.
64 65 66 |
# File 'lib/importu/backends.rb', line 64 def lookup(name) @registered[name.to_sym] end |
#names ⇒ Array<Symbol>
Returns all registered backend names.
71 72 73 |
# File 'lib/importu/backends.rb', line 71 def names @registered.keys end |
#register(name, klass) ⇒ Class
Registers a backend class.
80 81 82 |
# File 'lib/importu/backends.rb', line 80 def register(name, klass) @registered[name.to_sym] = klass end |