Class: Textus::Domain::Jobs::Registry
- Inherits:
-
Object
- Object
- Textus::Domain::Jobs::Registry
- Defined in:
- lib/textus/domain/jobs/registry.rb
Overview
Closed allow-list of runnable job types. The general ‘enqueue` surface (a later phase) can only push types registered here — that is the safety boundary that stops the “general runner” from running arbitrary code.
Defined Under Namespace
Classes: Entry
Instance Method Summary collapse
-
#initialize ⇒ Registry
constructor
A new instance of Registry.
- #lookup(type) ⇒ Object
-
#register(type, handler:, max_attempts: 3, required_role: nil) ⇒ Object
required_role: a role the caller must hold to enqueue this type via the general ‘enqueue` surface (nil = any caller).
- #registered?(type) ⇒ Boolean
Constructor Details
#initialize ⇒ Registry
Returns a new instance of Registry.
10 11 12 |
# File 'lib/textus/domain/jobs/registry.rb', line 10 def initialize @entries = {} end |
Instance Method Details
#lookup(type) ⇒ Object
26 27 28 29 30 31 32 33 |
# File 'lib/textus/domain/jobs/registry.rb', line 26 def lookup(type) @entries.fetch(type.to_s) do raise Textus::UsageError.new( "unregistered job type '#{type}'", hint: "register the type in Domain::Jobs::Registry before enqueueing it", ) end end |
#register(type, handler:, max_attempts: 3, required_role: nil) ⇒ Object
required_role: a role the caller must hold to enqueue this type via the general ‘enqueue` surface (nil = any caller). The closed allow-list is the primary safety boundary; this is defence-in-depth for destructive types.
18 19 20 |
# File 'lib/textus/domain/jobs/registry.rb', line 18 def register(type, handler:, max_attempts: 3, required_role: nil) @entries[type.to_s] = Entry.new(handler: handler, max_attempts: max_attempts, required_role: required_role) end |
#registered?(type) ⇒ Boolean
22 23 24 |
# File 'lib/textus/domain/jobs/registry.rb', line 22 def registered?(type) @entries.key?(type.to_s) end |