class Amber::Adapters::AdapterFactory

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

PubSub Adapters

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.cr

Class Method Summary

Class Method Detail

def self.available_pubsub_adapters : Array(String) #

Returns a list of available pub/sub adapter names.


[View source]
def self.available_session_adapters : Array(String) #

Returns a list of available session adapter names.


[View source]
def self.create_pubsub_adapter(adapter_name : String, **options) : PubSubAdapter #

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


[View source]
def self.create_session_adapter(adapter_name : String, **options) : SessionAdapter #

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


[View source]
def self.pubsub_adapter_registered?(name : String) : Bool #

Checks if a pub/sub adapter is registered.


[View source]
def self.register_pubsub_adapter(name : String, factory : Proc(PubSubAdapter)) #

Registers a pub/sub adapter factory.

@param name String identifier for the adapter @param factory Proc that creates the adapter instance


[View source]
def self.register_pubsub_adapter(name : String, &block : -> PubSubAdapter) #

Registers a pub/sub adapter factory using a block.

@param name String identifier for the adapter @param block Block that creates the adapter instance


[View source]
def self.register_session_adapter(name : String, factory : Proc(SessionAdapter)) #

Registers a session adapter factory.

@param name String identifier for the adapter @param factory Proc that creates the adapter instance


[View source]
def self.register_session_adapter(name : String, &block : -> SessionAdapter) #

Registers a session adapter factory using a block.

@param name String identifier for the adapter @param block Block that creates the adapter instance


[View source]
def self.session_adapter_registered?(name : String) : Bool #

Checks if a session adapter is registered.


[View source]