class
Amber::Adapters::AdapterFactory
- Amber::Adapters::AdapterFactory
- Reference
- Object
Overview
Factory for creating adapter instances based on configuration.
This factory provides a pluggable system for creating adapters without requiring hard dependencies on specific implementations. Users can register custom adapters and the factory will instantiate them based on string identifiers.
Built-in Adapters
Session Adapters
"memory"- MemorySessionAdapter (default, always available)
PubSub Adapters
"memory"- MemoryPubSubAdapter (default, always available)
Usage
# Using built-in adapters
session_adapter = AdapterFactory.create_session_adapter("memory")
pubsub_adapter = AdapterFactory.create_pubsub_adapter("memory")
# Registering custom adapters
AdapterFactory.register_session_adapter("database") do
DatabaseSessionAdapter.new(MyDB.connection)
end
AdapterFactory.register_pubsub_adapter("redis") do
RedisPubSubAdapter.new(Redis.new)
end
Defined in:
amber/adapters/adapter_factory.crClass Method Summary
-
.available_pubsub_adapters : Array(String)
Returns a list of available pub/sub adapter names.
-
.available_session_adapters : Array(String)
Returns a list of available session adapter names.
-
.create_pubsub_adapter(adapter_name : String, **options) : PubSubAdapter
Creates a pub/sub adapter instance based on the adapter name.
-
.create_session_adapter(adapter_name : String, **options) : SessionAdapter
Creates a session adapter instance based on the adapter name.
-
.pubsub_adapter_registered?(name : String) : Bool
Checks if a pub/sub adapter is registered.
-
.register_pubsub_adapter(name : String, factory : Proc(PubSubAdapter))
Registers a pub/sub adapter factory.
-
.register_pubsub_adapter(name : String, &block : -> PubSubAdapter)
Registers a pub/sub adapter factory using a block.
-
.register_session_adapter(name : String, factory : Proc(SessionAdapter))
Registers a session adapter factory.
-
.register_session_adapter(name : String, &block : -> SessionAdapter)
Registers a session adapter factory using a block.
-
.session_adapter_registered?(name : String) : Bool
Checks if a session adapter is registered.
Class Method Detail
Returns a list of available pub/sub adapter names.
Returns a list of available session adapter names.
Creates a pub/sub adapter instance based on the adapter name.
@param adapter_name The string identifier for the adapter type @param options Optional configuration hash for the adapter @return PubSubAdapter instance @raises ArgumentError if the adapter is not registered
Creates a session adapter instance based on the adapter name.
@param adapter_name The string identifier for the adapter type @param options Optional configuration hash for the adapter @return SessionAdapter instance @raises ArgumentError if the adapter is not registered
Checks if a pub/sub adapter is registered.
Registers a pub/sub adapter factory.
@param name String identifier for the adapter @param factory Proc that creates the adapter instance
Registers a pub/sub adapter factory using a block.
@param name String identifier for the adapter @param block Block that creates the adapter instance
Registers a session adapter factory.
@param name String identifier for the adapter @param factory Proc that creates the adapter instance
Registers a session adapter factory using a block.
@param name String identifier for the adapter @param block Block that creates the adapter instance
Checks if a session adapter is registered.