Class: Familia::Connection::StandaloneConnectionHandler
- Inherits:
-
BaseConnectionHandler
- Object
- BaseConnectionHandler
- Familia::Connection::StandaloneConnectionHandler
- Defined in:
- lib/familia/connection/handlers.rb
Overview
Handler for standalone DataType objects without a parent
Provides connection resolution for DataType objects that are created independently rather than being attached to a Horreum model. Checks for instance-level @dbclient first, then falls back to creating a connection based on logical_database option or global Familia connection.
This enables standalone DataType usage patterns like Rack::Session implementations where DataType objects need independent connection management and transaction support.
Instance Method Summary collapse
- #handle(uri) ⇒ Object
-
#initialize(data_type) ⇒ StandaloneConnectionHandler
constructor
A new instance of StandaloneConnectionHandler.
Constructor Details
#initialize(data_type) ⇒ StandaloneConnectionHandler
Returns a new instance of StandaloneConnectionHandler.
288 289 290 |
# File 'lib/familia/connection/handlers.rb', line 288 def initialize(data_type) @data_type = data_type end |
Instance Method Details
#handle(uri) ⇒ Object
292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 |
# File 'lib/familia/connection/handlers.rb', line 292 def handle(uri) # If a specific URI is provided, always use it to get a connection. if uri connection = Familia.dbclient(uri) Familia.trace :DBCLIENT_STANDALONE_DATATYPE, @data_type.dbkey, "Created standalone connection for specific URI: #{uri}" return connection end # Use instance @dbclient if explicitly set and no URI was passed instance_dbclient = @data_type.instance_variable_get(:@dbclient) if instance_dbclient Familia.trace :DBCLIENT_DATATYPE_INSTANCE, @data_type.dbkey, 'Using DataType instance @dbclient' return instance_dbclient end # Fall back to creating connection based on opts or global target_uri = @data_type.opts[:logical_database] connection = Familia.dbclient(target_uri) Familia.trace :DBCLIENT_STANDALONE_DATATYPE, @data_type.dbkey, "Created standalone connection for #{target_uri || 'default'}" connection end |