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 Operations so authorization, audit logging, and schema validation always fire.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ops:) ⇒ Context

Returns a new instance of Context.



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

def initialize(ops:)
  @ops = ops
  @role = ops.ctx.role
  @correlation_id = ops.ctx.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

Instance Method Details

#audit(verb, key:) ⇒ Object



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

def audit(verb, key:, **) = @ops.store.audit_log.append(role: @role, verb: verb, key: key, **)

#delete(key) ⇒ Object



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

def delete(key, **)       = @ops.delete(key, **)

#deps(key) ⇒ Object



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

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

#freshness(key) ⇒ Object



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

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

#get(key) ⇒ Object

read



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

def get(key)                = @ops.get(key)

#inspectObject



33
34
35
# File 'lib/textus/hooks/context.rb', line 33

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

#listObject



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

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

#publish_followup(event) ⇒ Object

fan-out



29
30
31
# File 'lib/textus/hooks/context.rb', line 29

def publish_followup(event, **)
  @ops.store.bus.publish(event, ctx: self, **)
end

#put(key) ⇒ Object

write (authorized + audited)



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

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