Class: Mammoth::LifecycleHooks
- Inherits:
-
Object
- Object
- Mammoth::LifecycleHooks
- Defined in:
- lib/mammoth/lifecycle_hooks.rb
Overview
Executes optional lifecycle callbacks around local Mammoth operations.
Hooks are intentionally in-process and explicit. They give extensions and future control agents stable observation points without changing the data plane or introducing remote behavior into OSS.
Constant Summary collapse
- EVENTS =
%i[ before_start after_start before_shutdown after_shutdown before_replay after_replay ].freeze
- EMPTY_CALLBACKS =
[nil].compact.freeze
Instance Attribute Summary collapse
-
#callbacks ⇒ Object
readonly
Returns the value of attribute callbacks.
Instance Method Summary collapse
- #call(event, context = {}) ⇒ void
-
#initialize(callbacks = {}) ⇒ LifecycleHooks
constructor
A new instance of LifecycleHooks.
Constructor Details
#initialize(callbacks = {}) ⇒ LifecycleHooks
Returns a new instance of LifecycleHooks.
23 24 25 |
# File 'lib/mammoth/lifecycle_hooks.rb', line 23 def initialize(callbacks = {}) @callbacks = normalize(callbacks || {}) end |
Instance Attribute Details
#callbacks ⇒ Object (readonly)
Returns the value of attribute callbacks.
20 21 22 |
# File 'lib/mammoth/lifecycle_hooks.rb', line 20 def callbacks @callbacks end |
Instance Method Details
#call(event, context = {}) ⇒ void
This method returns an undefined value.
30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/mammoth/lifecycle_hooks.rb', line 30 def call(event, context = {}) event = event.to_sym raise ConfigurationError, "unknown lifecycle hook: #{event}" unless EVENTS.include?(event) callback_list = callbacks.fetch(event, EMPTY_CALLBACKS) # @type var callback_list: untyped Array(callback_list).each do |callback| # @type var callback: untyped callback.call(context.merge(event: event)) end nil end |