Class: TypedBus::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/typed_bus/configuration.rb

Overview

Holds configurable defaults for the message bus system.

Three-tier cascade: Global → Bus → Channel. Each tier can override the one above using explicit values. The sentinel :use_default means "inherit from the tier above."

Examples:

Global defaults

TypedBus.configure do |config|
  config.timeout     = 60
  config.max_pending = 500
  config.throttle    = 0.5
  config.logger      = Logger.new($stdout)
  config.log_level   = Logger::DEBUG
end

Constant Summary collapse

DEFAULTS =
{
  timeout: 30,
  max_pending: nil,
  throttle: 0.0,
  logger: nil,
  log_level: Logger::INFO
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



30
31
32
33
34
35
36
# File 'lib/typed_bus/configuration.rb', line 30

def initialize
  @timeout     = DEFAULTS[:timeout]
  @max_pending = DEFAULTS[:max_pending]
  @throttle    = DEFAULTS[:throttle]
  @logger      = DEFAULTS[:logger]
  @log_level   = DEFAULTS[:log_level]
end

Instance Attribute Details

#log_levelObject

Returns the value of attribute log_level.



28
29
30
# File 'lib/typed_bus/configuration.rb', line 28

def log_level
  @log_level
end

#loggerObject

Returns the value of attribute logger.



28
29
30
# File 'lib/typed_bus/configuration.rb', line 28

def logger
  @logger
end

#max_pendingObject

Returns the value of attribute max_pending.



27
28
29
# File 'lib/typed_bus/configuration.rb', line 27

def max_pending
  @max_pending
end

#throttleObject

Returns the value of attribute throttle.



27
28
29
# File 'lib/typed_bus/configuration.rb', line 27

def throttle
  @throttle
end

#timeoutObject

Returns the value of attribute timeout.



27
28
29
# File 'lib/typed_bus/configuration.rb', line 27

def timeout
  @timeout
end

Instance Method Details

#initialize_copy(_source) ⇒ Object



67
68
69
70
# File 'lib/typed_bus/configuration.rb', line 67

def initialize_copy(_source)
  # All fields are scalars or intentionally shared (Logger).
  # No deep-copy needed.
end

#resolve(timeout: :use_default, max_pending: :use_default, throttle: :use_default) ⇒ Hash

Merge overrides on top of this configuration's values. Parameters set to :use_default inherit from this config.

Parameters:

  • timeout (Numeric, Symbol) (defaults to: :use_default)

    delivery ACK deadline

  • max_pending (Integer, nil, Symbol) (defaults to: :use_default)

    backpressure limit

  • throttle (Float, Symbol) (defaults to: :use_default)

    capacity ratio for adaptive backoff

Returns:

  • (Hash)

    resolved values



59
60
61
62
63
64
65
# File 'lib/typed_bus/configuration.rb', line 59

def resolve(timeout: :use_default, max_pending: :use_default, throttle: :use_default)
  {
    timeout:     timeout     == :use_default ? @timeout     : timeout,
    max_pending: max_pending == :use_default ? @max_pending : max_pending,
    throttle:    throttle    == :use_default ? @throttle    : throttle
  }
end