Class: Temporalio::Internal::Worker::WorkflowInstance::HandlerHash

Inherits:
SimpleDelegator
  • Object
show all
Defined in:
lib/temporalio/internal/worker/workflow_instance/handler_hash.rb

Overview

Hash for handlers that notifies when one is added. Only ‘[]=` and `store` can be used to mutate it.

Instance Method Summary collapse

Constructor Details

#initialize(initial_frozen_hash, definition_class, &on_new_definition) ⇒ HandlerHash

Returns a new instance of HandlerHash.



9
10
11
12
13
# File 'lib/temporalio/internal/worker/workflow_instance/handler_hash.rb', line 9

def initialize(initial_frozen_hash, definition_class, &on_new_definition)
  super(initial_frozen_hash)
  @definition_class = definition_class
  @on_new_definition = on_new_definition
end

Instance Method Details

#[]=(name, definition) ⇒ Object



15
16
17
# File 'lib/temporalio/internal/worker/workflow_instance/handler_hash.rb', line 15

def []=(name, definition)
  store(name, definition)
end

#store(name, definition) ⇒ Object

steep:ignore:start

Raises:

  • (ArgumentError)


20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/temporalio/internal/worker/workflow_instance/handler_hash.rb', line 20

def store(name, definition)
  raise ArgumentError, 'Name must be a string or nil' unless name.nil? || name.is_a?(String)

  unless definition.nil? || definition.is_a?(@definition_class)
    raise ArgumentError,
          "Value must be a #{@definition_class.name} or nil"
  end
  raise ArgumentError, 'Name does not match one in definition' if definition && name != definition.name

  # Do a copy-on-write op on the underlying frozen hash
  new_hash = __getobj__.dup
  new_hash[name] = definition
  __setobj__(new_hash.freeze)
  @on_new_definition&.call(definition) unless definition.nil?
  definition
end