Class: Familia::Connection::ParentDelegationHandler

Inherits:
Object
  • Object
show all
Includes:
Handler
Defined in:
lib/familia/connection/handlers.rb

Overview

Handler for delegating connection resolution to parent object

Used by DataType objects that are attached to a parent (Horreum instance or class). Delegates the connection resolution to the parent's dbclient method, which allows DataType objects to inherit connection settings, logical_database, and transaction context from their parent.

This preserves the existing architectural pattern where DataType objects owned by Horreum models use the parent's connection chain. This is the primary behavior for DataType objects in typical usage.

Examples:

Instance-level DataType with parent

user = User.new(userid: 'user_123')
user.tags  # DataType that delegates to user.dbclient

Class-level DataType with parent

User.global_users  # DataType that delegates to User.dbclient

Instance Method Summary collapse

Constructor Details

#initialize(data_type) ⇒ ParentDelegationHandler

Returns a new instance of ParentDelegationHandler.



330
331
332
# File 'lib/familia/connection/handlers.rb', line 330

def initialize(data_type)
  @data_type = data_type
end

Instance Method Details

#handle(uri) ⇒ Object



334
335
336
337
338
339
340
341
342
343
344
345
346
347
# File 'lib/familia/connection/handlers.rb', line 334

def handle(uri)
  return nil unless @data_type.parent

  # Delegate to parent's connection chain
  # Parent can be either a Horreum class or instance
  parent_connection = @data_type.parent.dbclient(uri)

  if parent_connection
    Familia.trace :DBCLIENT_PARENT_DELEGATION, @data_type.dbkey,
                 "Using parent connection from #{@data_type.parent.class}"
  end

  parent_connection
end