Class: Igniter::Store::Protocol::Handlers::EffectHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/igniter/store/protocol/handlers/effect_handler.rb

Overview

Effect descriptors describe the app-boundary persistence intent that a command lowers to. They are metadata-only and do not execute effects.

Constant Summary collapse

REQUIRED =
%i[name owner store_op write_kind].freeze
STORE_OPS =
%i[store_write store_append none].freeze
WRITE_KINDS =
%i[insert update append none].freeze

Instance Method Summary collapse

Constructor Details

#initialize(store) ⇒ EffectHandler

Returns a new instance of EffectHandler.



14
# File 'lib/igniter/store/protocol/handlers/effect_handler.rb', line 14

def initialize(store) = @store = store

Instance Method Details

#call(descriptor) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/igniter/store/protocol/handlers/effect_handler.rb', line 16

def call(descriptor)
  missing = REQUIRED.select { |field| descriptor[field].nil? }
  return Receipt.rejection("Missing required fields: #{missing.join(", ")}", kind: :effect) if missing.any?

  name = descriptor[:name].to_sym
  owner = descriptor[:owner].to_sym
  store_op = descriptor[:store_op].to_sym
  write_kind = descriptor[:write_kind].to_sym
  unless STORE_OPS.include?(store_op)
    return Receipt.rejection("Unsupported effect store_op: #{store_op.inspect}", kind: :effect)
  end
  unless WRITE_KINDS.include?(write_kind)
    return Receipt.rejection("Unsupported effect write_kind: #{write_kind.inspect}", kind: :effect)
  end

  normalized = descriptor.merge(
    name: name,
    owner: owner,
    store_op: store_op,
    write_kind: write_kind,
    lowers_to: token(descriptor[:lowers_to] || lowers_to_for(store_op)),
    boundary: token(descriptor[:boundary] || :app)
  )
  normalized[:source_operation] = token(descriptor[:source_operation]) if descriptor.key?(:source_operation)

  @store.schema_graph.register_effect_descriptor(normalized)
  Receipt.accepted(kind: :effect, name: name)
end