Class: DevCycle::EvalHooksRunner
- Inherits:
-
Object
- Object
- DevCycle::EvalHooksRunner
- Defined in:
- lib/devcycle-ruby-server-sdk/eval_hooks_runner.rb
Instance Attribute Summary collapse
-
#eval_hooks ⇒ Array<EvalHook>
readonly
Array of eval hooks to run.
Instance Method Summary collapse
-
#add_hook(eval_hook) ⇒ void
Adds an eval hook to the runner.
-
#clear_hooks ⇒ void
Clears all eval hooks from the runner.
-
#initialize(eval_hooks = []) ⇒ EvalHooksRunner
constructor
Initializes the EvalHooksRunner with an optional array of eval hooks.
-
#run_after_hooks(context) ⇒ void
Runs all after hooks with the given context.
-
#run_before_hooks(context) ⇒ HookContext
Runs all before hooks with the given context.
-
#run_error_hooks(context, error) ⇒ void
Runs all error hooks with the given context and error.
-
#run_finally_hooks(context) ⇒ void
Runs all finally hooks with the given context.
Constructor Details
#initialize(eval_hooks = []) ⇒ EvalHooksRunner
Initializes the EvalHooksRunner with an optional array of eval hooks
45 46 47 |
# File 'lib/devcycle-ruby-server-sdk/eval_hooks_runner.rb', line 45 def initialize(eval_hooks = []) @eval_hooks = eval_hooks || [] end |
Instance Attribute Details
#eval_hooks ⇒ Array<EvalHook> (readonly)
Returns Array of eval hooks to run.
41 42 43 |
# File 'lib/devcycle-ruby-server-sdk/eval_hooks_runner.rb', line 41 def eval_hooks @eval_hooks end |
Instance Method Details
#add_hook(eval_hook) ⇒ void
This method returns an undefined value.
Adds an eval hook to the runner
125 126 127 |
# File 'lib/devcycle-ruby-server-sdk/eval_hooks_runner.rb', line 125 def add_hook(eval_hook) @eval_hooks << eval_hook end |
#clear_hooks ⇒ void
This method returns an undefined value.
Clears all eval hooks from the runner
131 132 133 |
# File 'lib/devcycle-ruby-server-sdk/eval_hooks_runner.rb', line 131 def clear_hooks @eval_hooks.clear end |
#run_after_hooks(context) ⇒ void
This method returns an undefined value.
Runs all after hooks with the given context
76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/devcycle-ruby-server-sdk/eval_hooks_runner.rb', line 76 def run_after_hooks(context) @eval_hooks.each do |hook| next unless hook.after begin hook.after.call(context) rescue => e # Log error but continue with next hook raise AfterHookError.new(e., e, context) end end end |
#run_before_hooks(context) ⇒ HookContext
Runs all before hooks with the given context
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/devcycle-ruby-server-sdk/eval_hooks_runner.rb', line 53 def run_before_hooks(context) current_context = context @eval_hooks.each do |hook| next unless hook.before begin result = hook.before.call(current_context) # If the hook returns a new context, use it for subsequent hooks current_context = result if result.is_a?(DevCycle::HookContext) rescue => e # Raise BeforeHookError to allow client to handle and skip after hooks raise BeforeHookError.new(e., e, current_context) end end current_context end |
#run_error_hooks(context, error) ⇒ void
This method returns an undefined value.
Runs all error hooks with the given context and error
109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/devcycle-ruby-server-sdk/eval_hooks_runner.rb', line 109 def run_error_hooks(context, error) @eval_hooks.each do |hook| next unless hook.error begin hook.error.call(context, error) rescue => e # Log error but don't re-raise to prevent blocking evaluation warn "Error in error hook: #{e.}" end end end |
#run_finally_hooks(context) ⇒ void
This method returns an undefined value.
Runs all finally hooks with the given context
92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/devcycle-ruby-server-sdk/eval_hooks_runner.rb', line 92 def run_finally_hooks(context) @eval_hooks.each do |hook| next unless hook.on_finally begin hook.on_finally.call(context) rescue => e # Log error but don't re-raise to prevent blocking evaluation warn "Error in finally hook: #{e.}" end end end |