Class: Textus::Hooks::Context

Inherits:
Object
  • Object
show all
Defined in:
lib/textus/hooks/context.rb

Overview

A narrow handle passed to user hooks in place of the raw Store. All writes route back through the RoleScope so authorization, audit logging, and schema validation always fire.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(scope:) ⇒ Context

Returns a new instance of Context.



21
22
23
24
25
# File 'lib/textus/hooks/context.rb', line 21

def initialize(scope:)
  @scope          = scope
  @role           = scope.role
  @correlation_id = scope.correlation_id
end

Instance Attribute Details

#correlation_idObject (readonly)

Returns the value of attribute correlation_id.



9
10
11
# File 'lib/textus/hooks/context.rb', line 9

def correlation_id
  @correlation_id
end

#roleObject (readonly)

Returns the value of attribute role.



9
10
11
# File 'lib/textus/hooks/context.rb', line 9

def role
  @role
end

Class Method Details

.for(container:, call:) ⇒ Object



11
12
13
14
15
16
17
18
19
# File 'lib/textus/hooks/context.rb', line 11

def self.for(container:, call:)
  scope = Textus::RoleScope.new(
    container: container,
    role: call.role,
    correlation_id: call.correlation_id,
    dry_run: call.dry_run,
  )
  new(scope: scope)
end

Instance Method Details

#audit(verb, key:) ⇒ Object



45
46
47
# File 'lib/textus/hooks/context.rb', line 45

def audit(verb, key:, **)
  @scope.container.audit_log.append(role: @role, verb: verb, key: key, **)
end

#backendObject



27
28
29
# File 'lib/textus/hooks/context.rb', line 27

def backend
  @scope
end

#delete(key) ⇒ Object



43
# File 'lib/textus/hooks/context.rb', line 43

def delete(key, **)       = @scope.key_delete(key, **)

#deps(key) ⇒ Object



38
# File 'lib/textus/hooks/context.rb', line 38

def deps(key)               = @scope.deps(key)

#freshness(key) ⇒ Object



39
# File 'lib/textus/hooks/context.rb', line 39

def freshness(key)          = @scope.freshness(key)

#get(key) ⇒ Object

read — a pure-observation surface: nothing here ingests. Since ADR 0089 ‘get` itself is a pure read (the read-through that once forced this surface to opt out is gone, so the old re-entrancy/deadlock guard is no longer needed); `list`/`deps`/`freshness` are reads too. A hook observes current state and never triggers an I/O cascade.



36
# File 'lib/textus/hooks/context.rb', line 36

def get(key)                = pure_reader.call(key)

#inspectObject



54
55
56
# File 'lib/textus/hooks/context.rb', line 54

def inspect
  "#<Textus::Hooks::Context role=#{@role} correlation_id=#{@correlation_id}>"
end

#listObject



37
# File 'lib/textus/hooks/context.rb', line 37

def list(**)                = @scope.list(**)

#publish_followup(event) ⇒ Object

fan-out



50
51
52
# File 'lib/textus/hooks/context.rb', line 50

def publish_followup(event, **)
  @scope.container.events.publish(event, ctx: self, **)
end

#put(key) ⇒ Object

write (authorized + audited)



42
# File 'lib/textus/hooks/context.rb', line 42

def put(key, **)          = @scope.put(key, **)