Class: SenroUsecaser::Hook
- Inherits:
-
Object
- Object
- SenroUsecaser::Hook
- Extended by:
- DependsOn
- Defined in:
- lib/senro_usecaser/hook.rb
Overview
Base class for hooks with dependency injection support
Hook classes provide a way to define before/after/around hooks with access to the DI container and automatic dependency resolution.
Class Method Summary collapse
- .inherited(subclass) ⇒ Object private
Instance Method Summary collapse
-
#after(input, result) ⇒ Object
Called after the UseCase executes Override in subclass to add after logic.
-
#around(_input) ⇒ Object
Wraps the UseCase execution Override in subclass to add around logic.
-
#before(input) ⇒ Object
Called before the UseCase executes Override in subclass to add before logic.
-
#initialize(container:, use_case_namespace: nil) ⇒ Hook
constructor
Initializes the hook with dependencies resolved from the container.
-
#on_failure(input, result, context = nil) ⇒ Object
Called when the UseCase fails Override in subclass to add failure handling or rollback logic.
Methods included from DependsOn
copy_depends_on_to, declared_namespace, dependencies, dependency_types, depends_on, extended, namespace
Constructor Details
#initialize(container:, use_case_namespace: nil) ⇒ Hook
Initializes the hook with dependencies resolved from the container
: (container: Container, ?use_case_namespace: (Symbol | String)?) -> void
59 60 61 62 63 64 65 |
# File 'lib/senro_usecaser/hook.rb', line 59 def initialize(container:, use_case_namespace: nil) @_container = container @_use_case_namespace = use_case_namespace @_dependencies = {} #: Hash[Symbol, untyped] resolve_dependencies end |
Class Method Details
.inherited(subclass) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
50 51 52 53 |
# File 'lib/senro_usecaser/hook.rb', line 50 def inherited(subclass) super copy_depends_on_to(subclass) end |
Instance Method Details
#after(input, result) ⇒ Object
Called after the UseCase executes Override in subclass to add after logic
: (untyped, Result) -> void
79 80 81 |
# File 'lib/senro_usecaser/hook.rb', line 79 def after(input, result) # Override in subclass end |
#around(_input) ⇒ Object
87 88 89 |
# File 'lib/senro_usecaser/hook.rb', line 87 def around(_input) yield end |
#before(input) ⇒ Object
Called before the UseCase executes Override in subclass to add before logic
: (untyped) -> void
71 72 73 |
# File 'lib/senro_usecaser/hook.rb', line 71 def before(input) # Override in subclass end |
#on_failure(input, result, context = nil) ⇒ Object
Called when the UseCase fails Override in subclass to add failure handling or rollback logic
: (untyped, Result, ?RetryContext?) -> void
107 108 109 |
# File 'lib/senro_usecaser/hook.rb', line 107 def on_failure(input, result, context = nil) # Override in subclass end |