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.

Constant Summary collapse

EMPTY_COMPONENTS =
Ractor.make_shareable(
  {} # : Hash[untyped, untyped]
    .freeze
)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(scope:, components: EMPTY_COMPONENTS) ⇒ OrderingKey

Build an ordering key.

Parameters:

  • scope (#to_sym) —

    ordering scope

  • components (Hash) (defaults to: EMPTY_COMPONENTS) —

    key components



23
24
25
26
27
# File 'lib/cdc/core/ordering_key.rb', line 23

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

Instance Attribute Details

#components ⇒ Symbol, Hash{String=>Object} (readonly)

Returns:

  • (Symbol) —

    ordering scope

  • (Hash{String=>Object}) —

    normalized key components



17
18
19
# File 'lib/cdc/core/ordering_key.rb', line 17

def components
  @components
end

#scope ⇒ Symbol, Hash{String=>Object} (readonly)

Returns:

  • (Symbol) —

    ordering scope

  • (Hash{String=>Object}) —

    normalized key components



17
18
19
# File 'lib/cdc/core/ordering_key.rb', line 17

def scope
  @scope
end

Instance Method Details

#empty? ⇒ Boolean

Whether the key has no components.

Returns:

  • (Boolean) —

    true when the key has no components



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

def empty? = components.empty?

#to_h ⇒ Hash{String=>Object}

Convert the key into a Ractor-shareable hash.

Returns:

  • (Hash{String=>Object}) —

    Ractor-shareable ordering key representation



37
38
39
40
41
42
# File 'lib/cdc/core/ordering_key.rb', line 37

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