Class: Rake::Task

Inherits:
Object
  • Object
show all
Defined in:
lib/makit/tasks/task_monkey_patch.rb

Instance Method Summary collapse

Instance Method Details

#execute(*args) ⇒ Object

Enhanced execute method with hook support

This method wraps the original execute method to execute pre and post hooks around task execution. It handles errors gracefully and ensures hooks are always executed even if the task fails.



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/makit/tasks/task_monkey_patch.rb', line 58

def execute(*args)
  start_time = Time.now
  result = nil
  error = nil

  begin
    # Execute pre-task hooks

    Makit::Tasks::HookManager.execute_pre_hooks(name)

    # Execute the original task

    result = original_execute(*args)
  rescue StandardError => e
    error = e
    raise
  ensure
    # Execute post-task hooks (always runs, even on error)

    duration = Time.now - start_time
    Makit::Tasks::HookManager.execute_post_hooks(name, duration, result, error)
  end

  result
end

#invoke(*args) ⇒ Object

Enhanced invoke method with hook support

This method wraps the original invoke method to execute pre and post hooks around task execution. It handles errors gracefully and ensures hooks are always executed even if the task fails.



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/makit/tasks/task_monkey_patch.rb', line 27

def invoke(*args)
  start_time = Time.now
  result = nil
  error = nil

  begin
    # Execute pre-task hooks

    Makit::Tasks::HookManager.execute_pre_hooks(name)

    # Execute the original task

    result = original_invoke(*args)
  rescue StandardError => e
    error = e
    raise
  ensure
    # Execute post-task hooks (always runs, even on error)

    duration = Time.now - start_time
    Makit::Tasks::HookManager.execute_post_hooks(name, duration, result, error)
  end

  result
end

#original_executeObject



17
# File 'lib/makit/tasks/task_monkey_patch.rb', line 17

alias original_execute execute

#original_invokeObject

Store original methods before patching



16
# File 'lib/makit/tasks/task_monkey_patch.rb', line 16

alias original_invoke invoke