Class: Textus::Hooks::Context
- Inherits:
-
Object
- Object
- Textus::Hooks::Context
- 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
-
#correlation_id ⇒ Object
readonly
Returns the value of attribute correlation_id.
-
#role ⇒ Object
readonly
Returns the value of attribute role.
Class Method Summary collapse
Instance Method Summary collapse
- #audit(verb, key:) ⇒ Object
- #backend ⇒ Object
- #delete(key) ⇒ Object
- #deps(key) ⇒ Object
- #freshness(key) ⇒ Object
-
#get(key) ⇒ Object
read — a deliberately pure-observation surface: NOTHING here fetches (‘list`/`deps`/`freshness` don’t either).
-
#initialize(scope:) ⇒ Context
constructor
A new instance of Context.
- #inspect ⇒ Object
- #list ⇒ Object
-
#publish_followup(event) ⇒ Object
fan-out.
-
#put(key) ⇒ Object
write (authorized + audited).
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_id ⇒ Object (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 |
#role ⇒ Object (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
Instance Method Details
#audit(verb, key:) ⇒ Object
50 51 52 |
# File 'lib/textus/hooks/context.rb', line 50 def audit(verb, key:, **) @scope.container.audit_log.append(role: @role, verb: verb, key: key, **) end |
#backend ⇒ Object
27 28 29 |
# File 'lib/textus/hooks/context.rb', line 27 def backend @scope end |
#delete(key) ⇒ Object
48 |
# File 'lib/textus/hooks/context.rb', line 48 def delete(key, **) = @scope.delete(key, **) |
#deps(key) ⇒ Object
43 |
# File 'lib/textus/hooks/context.rb', line 43 def deps(key) = @scope.deps(key) |
#freshness(key) ⇒ Object
44 |
# File 'lib/textus/hooks/context.rb', line 44 def freshness(key) = @scope.freshness(key) |
#get(key) ⇒ Object
read — a deliberately pure-observation surface: NOTHING here fetches (‘list`/`deps`/`freshness` don’t either). The invariant is that a hook observes current state and never triggers an I/O cascade. ‘get` bypasses the read-through behavior (ADR 0062) and reads with fetch:false directly, because read-through inside a hook would: (1) fire fetch events → hooks →unbounded reentrancy; (2) spawn the orchestrator’s threads/fork from inside a hook callback; (3) probe the single-flight fetch lock its own enclosing fetch may hold (deadlock); (4) inject network latency into every hook read. With the merged Read::Get class, ‘fetch:false` (the method default) guarantees no orchestrator is built.
41 |
# File 'lib/textus/hooks/context.rb', line 41 def get(key) = pure_reader.call(key) |
#inspect ⇒ Object
59 60 61 |
# File 'lib/textus/hooks/context.rb', line 59 def inspect "#<Textus::Hooks::Context role=#{@role} correlation_id=#{@correlation_id}>" end |
#list ⇒ Object
42 |
# File 'lib/textus/hooks/context.rb', line 42 def list(**) = @scope.list(**) |
#publish_followup(event) ⇒ Object
fan-out
55 56 57 |
# File 'lib/textus/hooks/context.rb', line 55 def publish_followup(event, **) @scope.container.events.publish(event, ctx: self, **) end |
#put(key) ⇒ Object
write (authorized + audited)
47 |
# File 'lib/textus/hooks/context.rb', line 47 def put(key, **) = @scope.put(key, **) |