Class: PGMQ::Transaction::TransactionalClient

Inherits:
Object
  • Object
show all
Defined in:
lib/pgmq/transaction.rb

Overview

Minimal wrapper that ensures all operations use the transaction connection

Instance Method Summary collapse

Constructor Details

#initialize(parent, conn) ⇒ TransactionalClient

Returns a new instance of TransactionalClient.

Parameters:

  • parent (PGMQ::Client)

    parent client instance

  • conn (PG::Connection)

    transaction connection



55
56
57
58
59
60
61
# File 'lib/pgmq/transaction.rb', line 55

def initialize(
  parent,
  conn
)
  @parent = parent
  @conn = conn
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method) ⇒ Object

Forward all method calls to parent, but use our transaction connection

Parameters:

  • method (Symbol)

    method name

Returns:

  • (Object)

    result of method call



66
67
68
# File 'lib/pgmq/transaction.rb', line 66

def method_missing(method, ...)
  @parent.respond_to?(method, true) ? @parent.__send__(method, ...) : super
end

Instance Method Details

#connectionObject

Expose parent’s connection (for tests/inspection)



87
88
89
# File 'lib/pgmq/transaction.rb', line 87

def connection
  @parent.connection
end

#respond_to_missing?(method, include_private = false) ⇒ Boolean

Check if method exists on parent

Parameters:

  • method (Symbol)

    method name

  • include_private (Boolean) (defaults to: false)

    include private methods

Returns:

  • (Boolean)

    true if method exists



74
75
76
77
78
79
# File 'lib/pgmq/transaction.rb', line 74

def respond_to_missing?(
  method,
  include_private = false
)
  @parent.respond_to?(method, include_private) || super
end

#with_connection {|@conn| ... } ⇒ Object

Inject our transaction connection instead of using the pool

Yields:

  • (@conn)


82
83
84
# File 'lib/pgmq/transaction.rb', line 82

def with_connection
  yield @conn
end