Class: JobWorkflow::HookRegistry

Inherits:
Object
  • Object
show all
Defined in:
lib/job_workflow/hook_registry.rb,
sig/generated/job_workflow/hook_registry.rbs

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeHookRegistry

: () -> void



6
7
8
9
10
11
# File 'lib/job_workflow/hook_registry.rb', line 6

def initialize
  self.before_hooks = [] #: Array[Hook]
  self.after_hooks = [] #: Array[Hook]
  self.around_hooks = [] #: Array[Hook]
  self.error_hooks = [] #: Array[ErrorHook]
end

Instance Attribute Details

#after_hooksArray[Hook]

Signature:

  • Array[Hook]

Returns:



56
57
58
# File 'lib/job_workflow/hook_registry.rb', line 56

def after_hooks
  @after_hooks
end

#around_hooksArray[Hook]

Signature:

  • Array[Hook]

Returns:



57
58
59
# File 'lib/job_workflow/hook_registry.rb', line 57

def around_hooks
  @around_hooks
end

#before_hooksArray[Hook]

Signature:

  • Array[Hook]

Returns:



55
56
57
# File 'lib/job_workflow/hook_registry.rb', line 55

def before_hooks
  @before_hooks
end

#error_hooksArray[ErrorHook]

Signature:

  • Array[ErrorHook]

Returns:



58
59
60
# File 'lib/job_workflow/hook_registry.rb', line 58

def error_hooks
  @error_hooks
end

Instance Method Details

#add_after_hook(task_names:, block:) ⇒ void

This method returns an undefined value.

: (task_names: Array, block: ^(Context, ?TaskCallable) -> void) -> void

Parameters:



19
20
21
# File 'lib/job_workflow/hook_registry.rb', line 19

def add_after_hook(task_names:, block:)
  after_hooks << Hook.new(task_names:, block:)
end

#add_around_hook(task_names:, block:) ⇒ void

This method returns an undefined value.

: (task_names: Array, block: ^(Context, ?TaskCallable) -> void) -> void

Parameters:



24
25
26
# File 'lib/job_workflow/hook_registry.rb', line 24

def add_around_hook(task_names:, block:)
  around_hooks << Hook.new(task_names:, block:)
end

#add_before_hook(task_names:, block:) ⇒ void

This method returns an undefined value.

: (task_names: Array, block: ^(Context, ?TaskCallable) -> void) -> void

Parameters:



14
15
16
# File 'lib/job_workflow/hook_registry.rb', line 14

def add_before_hook(task_names:, block:)
  before_hooks << Hook.new(task_names:, block:)
end

#add_error_hook(task_names:, block:) ⇒ void

This method returns an undefined value.

: (task_names: Array, block: ^(Context, StandardError, Task) -> void) -> void

Parameters:

  • task_names: (Array[Symbol])
  • block: (^(Context, StandardError, Task) -> void)


29
30
31
# File 'lib/job_workflow/hook_registry.rb', line 29

def add_error_hook(task_names:, block:)
  error_hooks << ErrorHook.new(task_names:, block:)
end

#after_hooks_for(task_name) ⇒ Array[Hook]

: (Symbol) -> Array

Parameters:

  • (Symbol)

Returns:



39
40
41
# File 'lib/job_workflow/hook_registry.rb', line 39

def after_hooks_for(task_name)
  hooks_for(after_hooks, task_name)
end

#around_hooks_for(task_name) ⇒ Array[Hook]

: (Symbol) -> Array

Parameters:

  • (Symbol)

Returns:



44
45
46
# File 'lib/job_workflow/hook_registry.rb', line 44

def around_hooks_for(task_name)
  hooks_for(around_hooks, task_name)
end

#before_hooks_for(task_name) ⇒ Array[Hook]

: (Symbol) -> Array

Parameters:

  • (Symbol)

Returns:



34
35
36
# File 'lib/job_workflow/hook_registry.rb', line 34

def before_hooks_for(task_name)
  hooks_for(before_hooks, task_name)
end

#error_hooks_for(task_name) ⇒ Array[ErrorHook]

: (Symbol) -> Array

Parameters:

  • (Symbol)

Returns:



49
50
51
# File 'lib/job_workflow/hook_registry.rb', line 49

def error_hooks_for(task_name)
  hooks_for(error_hooks, task_name)
end

#hooks_for(arg0, arg1) ⇒ Array[Hook] #hooks_for(arg0, arg1) ⇒ Array[ErrorHook]

: (Array, Symbol) -> Array : (Array, Symbol) -> Array

Overloads:

  • #hooks_for(arg0, arg1) ⇒ Array[Hook]

    Parameters:

    • arg0 (Array[Hook])
    • arg1 (Symbol)

    Returns:

  • #hooks_for(arg0, arg1) ⇒ Array[ErrorHook]

    Parameters:

    Returns:



62
63
64
# File 'lib/job_workflow/hook_registry.rb', line 62

def hooks_for(hooks, task_name)
  hooks.filter { |hook| hook.applies_to?(task_name) }
end