Class: Familia::Connection::StandaloneConnectionHandler
- Inherits:
-
Object
- Object
- Familia::Connection::StandaloneConnectionHandler
- Includes:
- Handler
- 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.
372 373 374 |
# File 'lib/familia/connection/handlers.rb', line 372 def initialize(data_type) @data_type = data_type end |
Instance Method Details
#handle(uri) ⇒ Object
376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 |
# File 'lib/familia/connection/handlers.rb', line 376 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 |