Class: CDC::Core::OrderingKey

Inherits:
Object
  • Object
show all
Defined in:
lib/cdc/core/ordering_key.rb

Overview

Immutable grouping key for ordering-related dispatch.

OrderingKey captures the scope plus the components that define a particular ordered lane. It does not choose an execution strategy.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(scope:, components: {}) ⇒ OrderingKey

Build an ordering key.

Parameters:

  • scope (#to_sym)

    ordering scope

  • components (Hash) (defaults to: {})

    key components



18
19
20
21
22
# File 'lib/cdc/core/ordering_key.rb', line 18

def initialize(scope:, components: {})
  @scope = OrderingScope.normalize(scope)
  @components = EventMetadata.new(components).to_h
  Ractor.make_shareable(self)
end

Instance Attribute Details

#componentsSymbol, Hash{String=>Object} (readonly)

Returns:

  • (Symbol)

    ordering scope

  • (Hash{String=>Object})

    normalized key components



12
13
14
# File 'lib/cdc/core/ordering_key.rb', line 12

def components
  @components
end

#scopeSymbol, Hash{String=>Object} (readonly)

Returns:

  • (Symbol)

    ordering scope

  • (Hash{String=>Object})

    normalized key components



12
13
14
# File 'lib/cdc/core/ordering_key.rb', line 12

def scope
  @scope
end

Instance Method Details

#empty?Boolean

Whether the key has no components.

Returns:

  • (Boolean)


27
# File 'lib/cdc/core/ordering_key.rb', line 27

def empty? = components.empty?

#to_hHash{String=>Object}

Convert the key into a Ractor-shareable hash.

Returns:

  • (Hash{String=>Object})


32
33
34
35
36
37
# File 'lib/cdc/core/ordering_key.rb', line 32

def to_h
  Ractor.make_shareable({
    'scope' => scope,
    'components' => components
  }.freeze)
end