makit 0.0.111 → 0.0.126

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (65) hide show
  1. checksums.yaml +4 -4
  2. data/lib/makit/cli/repository_commands.rb +1 -1
  3. data/lib/makit/commands/middleware/cache.rb +3 -3
  4. data/lib/makit/commands/middleware/command_logger.rb +33 -45
  5. data/lib/makit/commands/request.rb +63 -1
  6. data/lib/makit/commands/runner.rb +56 -5
  7. data/lib/makit/commands/strategies/base.rb +13 -2
  8. data/lib/makit/commands/strategies/synchronous.rb +11 -6
  9. data/lib/makit/commands.rb +8 -0
  10. data/lib/makit/configuration/gitlab_helper.rb +0 -2
  11. data/lib/makit/configuration/project.rb +48 -8
  12. data/lib/makit/configuration/step.rb +3 -3
  13. data/lib/makit/content/default_gitignore.txt +226 -0
  14. data/lib/makit/directories.rb +3 -4
  15. data/lib/makit/docs/files.rb +1 -1
  16. data/lib/makit/docs/rake.rb +1 -1
  17. data/lib/makit/dotnet/cli.rb +69 -65
  18. data/lib/makit/dotnet/project.rb +71 -7
  19. data/lib/makit/examples/runner.rb +2 -2
  20. data/lib/makit/logging/configuration.rb +9 -6
  21. data/lib/makit/logging/format_registry.rb +84 -84
  22. data/lib/makit/logging/formatters/console_formatter.rb +22 -9
  23. data/lib/makit/logging/log_request.rb +6 -2
  24. data/lib/makit/logging/logger.rb +45 -5
  25. data/lib/makit/logging/sinks/base.rb +91 -91
  26. data/lib/makit/logging/sinks/structured.rb +123 -129
  27. data/lib/makit/logging/sinks/unified_file_sink.rb +39 -46
  28. data/lib/makit/logging.rb +45 -1
  29. data/lib/makit/mp/project_mp.rb +6 -6
  30. data/lib/makit/mp/string_mp.rb +108 -265
  31. data/lib/makit/serializer.rb +14 -1
  32. data/lib/makit/services/builder.rb +5 -5
  33. data/lib/makit/services/repository_manager.rb +8 -6
  34. data/lib/makit/setup/classlib.rb +44 -7
  35. data/lib/makit/setup/gem.rb +268 -250
  36. data/lib/makit/setup/razorclasslib.rb +91 -0
  37. data/lib/makit/setup/runner.rb +36 -22
  38. data/lib/makit/setup.rb +5 -0
  39. data/lib/makit/symbols.rb +10 -1
  40. data/lib/makit/tasks/at_exit.rb +3 -1
  41. data/lib/makit/tasks/build.rb +16 -12
  42. data/lib/makit/tasks/clean.rb +2 -0
  43. data/lib/makit/tasks/configure.rb +10 -0
  44. data/lib/makit/tasks/format.rb +10 -0
  45. data/lib/makit/tasks/hook_manager.rb +160 -8
  46. data/lib/makit/tasks/init.rb +2 -0
  47. data/lib/makit/tasks/integrate.rb +17 -3
  48. data/lib/makit/tasks/pull_incoming.rb +6 -5
  49. data/lib/makit/tasks/setup.rb +10 -3
  50. data/lib/makit/tasks/sync.rb +13 -7
  51. data/lib/makit/tasks/tag.rb +16 -0
  52. data/lib/makit/tasks/task_monkey_patch.rb +58 -56
  53. data/lib/makit/tasks/test.rb +22 -0
  54. data/lib/makit/tasks/update.rb +18 -0
  55. data/lib/makit/tasks.rb +20 -5
  56. data/lib/makit/v1/makit.v1_pb.rb +1 -0
  57. data/lib/makit/version.rb +1 -1
  58. data/lib/makit/version_util.rb +21 -0
  59. data/lib/makit copy.rb +44 -0
  60. data/lib/makit.rb +31 -0
  61. metadata +118 -13
  62. data/lib/makit/command_runner.rb +0 -463
  63. data/lib/makit/commands/compatibility.rb +0 -365
  64. data/lib/makit/commands/middleware/unified_logger.rb +0 -243
  65. data/lib/makit/task_hooks.rb +0 -125
@@ -1,38 +1,52 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require_relative "classlib"
3
4
  require_relative "gem"
5
+ require_relative "razorclasslib"
6
+ require_relative "../content/default_gitignore"
4
7
 
5
8
  module Makit
6
9
  module Setup
7
10
  class Runner
8
11
  def self.run
9
12
 
13
+ # if a .git directory exists, then make sure we have a .gitignore
14
+ if File.exist?(".git")
15
+ if !File.exist?(".gitignore")
16
+ File.write(".gitignore", Makit::Content::GITIGNORE)
17
+ end
18
+ end
10
19
  # open .makit.json and get project type, to determine which setup to run
11
- if File.exist?(".makit.json")
12
- begin
13
- project = Makit::Serializer.open(".makit.json", Makit::Configuration::Project)
20
+ return unless File.exist?(".makit.json")
14
21
 
15
- # Check if the file contains compact JSON and resave as pretty JSON
16
- current_content = File.read(".makit.json")
17
- pretty_content = project.to_json_pretty
22
+ begin
23
+ project = Makit::Serializer.open(".makit.json", Makit::Configuration::Project)
18
24
 
19
- # Only rewrite if the content is different (i.e., if it was compact)
20
- if current_content.strip != pretty_content.strip
21
- File.write(".makit.json", pretty_content)
22
- end
23
- rescue
24
- raise "Error opening .makit.json"
25
- end
26
- project_type = project.project_type
27
- case project_type
28
- when "classlib"
29
- Makit::Setup::ClassLib.run
30
- when "gem"
31
- Makit::Setup::Gem.run
32
- else
33
- Makit::Logging.default_logger.warn("Unsupported project type: #{project_type}")
34
- #puts "Unsupported project type: #{project_type}"
25
+ # Update version to match VERSION constant only if project version is truly empty
26
+ if defined?(Makit::VERSION) && (project.version.nil? || project.version.empty?)
27
+ project.version = Makit::VERSION
35
28
  end
29
+
30
+ # Check if the file contains compact JSON and resave as pretty JSON
31
+ current_content = File.read(".makit.json")
32
+ pretty_content = project.to_json_pretty
33
+
34
+ # Only rewrite if the content is different (i.e., if it was compact or version changed)
35
+ File.write(".makit.json", pretty_content) if current_content.strip != pretty_content.strip
36
+ rescue StandardError
37
+ raise "Error opening .makit.json"
38
+ end
39
+ project_type = project.project_type
40
+ case project_type
41
+ when "classlib"
42
+ Makit::Setup::ClassLib.run
43
+ when "razorclasslib"
44
+ Makit::Setup::RazorClassLib.run
45
+ when "gem"
46
+ Makit::Setup::Gem.run
47
+ else
48
+ Makit::Logging.default_logger.warn("Unsupported project type: #{project_type}")
49
+ # puts "Unsupported project type: #{project_type}"
36
50
  end
37
51
  end
38
52
  end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "setup/runner"
4
+ require_relative "setup/classlib"
5
+ require_relative "setup/gem"
data/lib/makit/symbols.rb CHANGED
@@ -1,6 +1,15 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "rainbow"
3
+ begin
4
+ require "rainbow"
5
+ rescue LoadError
6
+ # rainbow gem not available, define a no-op rainbow method
7
+ class String
8
+ def rainbow
9
+ self
10
+ end
11
+ end
12
+ end
4
13
 
5
14
  # https://symbl.cc/en/unicode/table/
6
15
  module Makit
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "English"
2
4
 
3
5
  at_exit do
@@ -9,5 +11,5 @@ at_exit do
9
11
  Makit::Logging.default_logger.info(message)
10
12
  else
11
13
  Makit::Logging.default_logger.error(message)
12
- end # display the humanized duration of the rake execution
14
+ end
13
15
  end
@@ -1,18 +1,22 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative "../setup/runner"
2
4
 
3
- desc "Build project artifacts.."
4
- task :build do
5
- # load the default project configuration
6
- project = Makit::Configuration::Project.default
5
+ if File.exist?(".makit.json")
6
+ desc "Build project artifacts.."
7
+ task :build do
8
+ Makit::Logging.default_logger.task_start("build")
9
+ # load the default project configuration
10
+ # puts "loading project configuration"
11
+ project = Makit::Configuration::Project.default
7
12
 
8
- # for each step in the project configuration, run the commands
9
- project.steps.each do |step|
10
- step.commands.each do |command|
11
- request = Makit::Commands::Request.from_string(command)
12
- result = Makit::Commands::Runner.default.execute(request)
13
+ # if the project has a build step, run the commands
14
+ build_step = project.steps.find { |step| step.name == "build" }
15
+ build_step&.commands&.each do |command|
16
+ request = Makit::Commands::Request.from_string(command).exit_on_failure(true).show_stderr(true)
17
+ Makit::Commands::Runner.default.execute(request)
13
18
  end
14
19
  end
15
-
16
- # Make sure the build commands are in the project configuration
17
-
20
+ else
21
+ Makit::Logging.default_logger.debug("Project not configured, skipping setup task definition")
18
22
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "rake/clean"
2
4
  require_relative "../git/repository"
3
5
  require_relative "../commands/runner"
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ desc "Configure the project"
4
+ task :configure do
5
+ project = Makit::Configuration::Project.default
6
+ if defined?(GIT_REMOTE_URL)
7
+ project.git_remote_url = GIT_REMOTE_URL
8
+ project.save
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ desc "Format project files"
4
+ task :format do
5
+ "rufo .".try if File.exist?("Gemfile") || File.exist?("Rakefile")
6
+
7
+ Dir.glob("**/*.csproj").each do |file|
8
+ "dotnet format #{file}".run
9
+ end
10
+ end
@@ -2,6 +2,7 @@
2
2
 
3
3
  require "set"
4
4
  require "colorize"
5
+ require "fileutils"
5
6
 
6
7
  # Task hooks system for Makit
7
8
  #
@@ -41,6 +42,12 @@ module Makit
41
42
  @excluded_tasks = Set.new
42
43
  @logged_tasks = Set.new
43
44
 
45
+ # Timing functionality
46
+ @timing_enabled = false
47
+ @task_stack = []
48
+ @performance_log = "artifacts/task_performance.log"
49
+ @hooks_installed = false
50
+
44
51
  class << self
45
52
  # @return [Array<Proc>] Global pre-task hooks
46
53
  attr_reader :pre_hooks
@@ -57,6 +64,15 @@ module Makit
57
64
  # @return [Set<String>] Tasks excluded from hook execution
58
65
  attr_reader :excluded_tasks
59
66
 
67
+ # @return [Boolean] Whether timing is enabled
68
+ attr_reader :timing_enabled
69
+
70
+ # @return [Array<Hash>] Stack of currently executing tasks
71
+ attr_reader :task_stack
72
+
73
+ # @return [String] Path to performance log file
74
+ attr_reader :performance_log
75
+
60
76
  # Add a global pre-task hook
61
77
  #
62
78
  # The hook will be executed before every task runs.
@@ -118,6 +134,15 @@ module Makit
118
134
  def execute_pre_hooks(task_name)
119
135
  return if excluded?(task_name)
120
136
 
137
+ # Track timing if enabled
138
+ if timing_enabled?
139
+ @task_stack.push({
140
+ name: task_name,
141
+ start_time: Time.now,
142
+ level: @task_stack.length,
143
+ })
144
+ end
145
+
121
146
  # Execute global pre-hooks
122
147
  @pre_hooks.each { |hook| hook.call(task_name) }
123
148
 
@@ -136,6 +161,18 @@ module Makit
136
161
  def execute_post_hooks(task_name, duration, result, error)
137
162
  return if excluded?(task_name)
138
163
 
164
+ # Handle timing if enabled
165
+ if timing_enabled?
166
+ task_info = @task_stack.pop
167
+ if task_info && task_info[:name] == task_name && (duration > 0.1)
168
+ # Log performance for tasks that took longer than 0.1 seconds
169
+ log_task_performance(task_name, duration, task_info[:level])
170
+ end
171
+
172
+ # Log task failure if there was an error
173
+ log_task_failure(task_name, duration, error, task_info&.dig(:level) || 0) if error
174
+ end
175
+
139
176
  # Execute global post-hooks
140
177
  @post_hooks.each { |hook| hook.call(task_name, duration, result, error) }
141
178
 
@@ -189,9 +226,82 @@ module Makit
189
226
  task_specific_post_hooks: @task_specific_post_hooks.values.flatten.size,
190
227
  tasks_with_pre_hooks: @task_specific_pre_hooks.keys,
191
228
  tasks_with_post_hooks: @task_specific_post_hooks.keys,
229
+ timing_enabled: @timing_enabled,
230
+ task_stack_depth: @task_stack.size,
192
231
  }
193
232
  end
194
233
 
234
+ # Enable task timing and performance logging
235
+ #
236
+ # @return [void]
237
+ def enable_timing!
238
+ @timing_enabled = true
239
+ puts "🔧 Task timing enabled".colorize(:grey) if defined?(String.instance_method(:colorize))
240
+ end
241
+
242
+ # Disable task timing and performance logging
243
+ #
244
+ # @return [void]
245
+ def disable_timing!
246
+ @timing_enabled = false
247
+ end
248
+
249
+ # Check if timing is enabled
250
+ #
251
+ # @return [Boolean] true if timing is enabled
252
+ def timing_enabled?
253
+ @timing_enabled == true
254
+ end
255
+
256
+ # Clear performance logs
257
+ #
258
+ # @return [void]
259
+ def clear_performance_logs
260
+ FileUtils.rm_f(@performance_log)
261
+ FileUtils.rm_f("artifacts/task_failures.log")
262
+ end
263
+
264
+ # Setup task hooks by monkey patching Rake::Task
265
+ #
266
+ # This method patches the Rake::Task#execute method to automatically
267
+ # call pre and post hooks for all task executions.
268
+ #
269
+ # @return [void]
270
+ def setup!
271
+ return if @hooks_installed
272
+
273
+ Rake::Task.class_eval do
274
+ alias_method :makit_original_execute, :execute
275
+
276
+ def execute(args = nil)
277
+ start_time = Time.now
278
+ error = nil
279
+ result = nil
280
+
281
+ begin
282
+ # Execute pre-hooks
283
+ Makit::Tasks::HookManager.execute_pre_hooks(name)
284
+
285
+ # Execute the original task
286
+ result = makit_original_execute(args)
287
+ rescue StandardError => e
288
+ error = e
289
+ raise
290
+ ensure
291
+ # Calculate duration
292
+ duration = Time.now - start_time
293
+
294
+ # Execute post-hooks
295
+ Makit::Tasks::HookManager.execute_post_hooks(name, duration, result, error)
296
+ end
297
+
298
+ result
299
+ end
300
+ end
301
+
302
+ @hooks_installed = true
303
+ end
304
+
195
305
  # Setup default task hooks
196
306
  #
197
307
  # This method sets up the default task hooks that provide basic
@@ -199,7 +309,10 @@ module Makit
199
309
  #
200
310
  # @return [void]
201
311
  def setup_default_hooks
202
- # Only setup if no hooks are already registered
312
+ # Setup the monkey patching first
313
+ setup!
314
+
315
+ # Only setup default hooks if no hooks are already registered
203
316
  return unless @pre_hooks.empty? && @post_hooks.empty?
204
317
 
205
318
  # Exclude the init task from hooks to prevent duplication
@@ -218,17 +331,56 @@ module Makit
218
331
  end
219
332
 
220
333
  def log_task_start(task_name)
221
- #return if @logged_tasks.include?(task_name)
222
- #@logged_tasks.add(task_name)
223
- #Makit::Logging.info("#{task_name}".colorize(:white).bold)
334
+ # return if @logged_tasks.include?(task_name)
335
+ # @logged_tasks.add(task_name)
336
+ # Makit::Logging.info("#{task_name}".colorize(:white).bold)
224
337
  end
225
338
 
226
339
  def log_task_completion(task_name, duration, result, error)
227
- #Makit::Logging.info("#{task_name}".colorize(:white).bold)
228
- #Makit::Logging.info("Task completed".colorize(:green).bold)
229
- #Makit::Logging.info("Duration: #{duration.round(2)}s".colorize(:green).bold)
340
+ # Makit::Logging.info("#{task_name}".colorize(:white).bold)
341
+ # Makit::Logging.info("Task completed".colorize(:green).bold)
342
+ # Makit::Logging.info("Duration: #{duration.round(2)}s".colorize(:green).bold)
230
343
  # Makit::Logging.info("Result: #{result}".colorize(:green).bold)
231
- #Makit::Logging.info("Error: #{error}".colorize(:red).bold)
344
+ # Makit::Logging.info("Error: #{error}".colorize(:red).bold)
345
+ end
346
+
347
+ private
348
+
349
+ # Log task performance to file
350
+ #
351
+ # @param name [String] task name
352
+ # @param duration [Float] execution duration
353
+ # @param level [Integer] nesting level
354
+ # @return [void]
355
+ def log_task_performance(name, duration, level)
356
+ return if ENV["CI"] == "true" && duration < 1.0
357
+
358
+ FileUtils.mkdir_p("artifacts")
359
+ File.open(@performance_log, "a") do |f|
360
+ f.puts "#{Time.now.strftime("%Y-%m-%d %H:%M:%S")},#{name},#{duration.round(4)},#{level}"
361
+ end
362
+ rescue StandardError
363
+ # Silently fail performance logging to not interrupt tasks
364
+ end
365
+
366
+ # Log task failure to file
367
+ #
368
+ # @param name [String] task name
369
+ # @param duration [Float] execution duration
370
+ # @param error [Exception] the error that occurred
371
+ # @param level [Integer] nesting level
372
+ # @return [void]
373
+ def log_task_failure(name, duration, error, _level)
374
+ failure_log = "artifacts/task_failures.log"
375
+ FileUtils.mkdir_p("artifacts")
376
+
377
+ File.open(failure_log, "a") do |f|
378
+ timestamp = Time.now.strftime("%Y-%m-%d %H:%M:%S")
379
+ message = error.message.gsub(",", ";")
380
+ f.puts "#{timestamp},#{name},#{duration.round(4)},#{error.class.name},#{message}"
381
+ end
382
+ rescue StandardError
383
+ # Silently fail error logging
232
384
  end
233
385
  end
234
386
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  Rake.application.top_level_tasks.unshift("init")
2
4
 
3
5
  task :init do
@@ -1,15 +1,29 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative "../git/repository"
2
4
 
3
- if Makit::Git::Repository.git_repo?
5
+ if Dir.exist?(".git")
4
6
  desc "Integrate changes into the git repository."
5
7
  task :integrate do
8
+ Makit::Logging.default_logger.task_start("integrate")
6
9
  unstaged_files = Makit::Git::Repository.unstaged_files
7
10
  untracked_files = Makit::Git::Repository.untracked_files
8
11
  if unstaged_files.length.positive? || untracked_files.length.positive?
9
- Makit::Git::CLI.integrate
12
+ #Makit::Git::CLI.integrate
13
+ #return unless Repository.git_repo? && !Repository.detached
14
+
15
+ ## check for unstaged or untracked files
16
+ # unstaged_files = `git status --porcelain`.split("\n")
17
+ # untracked_files = `git ls-files --others --exclude-standard`.split("\n")
18
+ # return unless unstaged_files.length.positive? || untracked_files.length.positive?
19
+
20
+ "git add .".try
21
+ "git commit -m \"integrate\"".run unless Makit::Git::Repository.clean?
10
22
  else
11
23
  Makit::Logging.default_logger.info("No unstaged or untracked files found")
12
- #puts " No unstaged or untracked files found".colorize(:grey)
24
+ # puts " No unstaged or untracked files found".colorize(:grey)
13
25
  end
14
26
  end
27
+ else
28
+ Makit::Logging.default_logger.debug("Not a git repository, skipping integrate")
15
29
  end
@@ -1,12 +1,13 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative "../git/repository"
2
4
 
3
5
  if Makit::Git::Repository.git_repo?
4
6
  desc "pull changes from the remote branch, preferring incoming changes for conflicts"
5
7
  task :pull_incoming do
6
- Makit::TaskInfo.track(:pull_incoming) do
7
- # Makit::SHOW.task(:pull_incoming)
8
- puts " git branch is ".colorize(:grey) + Makit::Git::Repository.branch.to_s.colorize(:green)
9
- "git pull origin #{Makit::Git::Repository.branch} -X theirs".try
10
- end
8
+ Makit::Logging.default_logger.task_start("pull_incoming")
9
+ # Makit::SHOW.task(:pull_incoming)
10
+ puts " git branch is ".colorize(:grey) + Makit::Git::Repository.branch.to_s.colorize(:green)
11
+ "git pull origin #{Makit::Git::Repository.branch} -X theirs".try
11
12
  end
12
13
  end
@@ -1,6 +1,13 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative "../setup/runner"
2
4
 
3
- desc "Setup project files.."
4
- task :setup do
5
- Makit::Setup::Runner.run
5
+ if File.exist?(".makit.json")
6
+ desc "Setup project files.."
7
+ task :setup do
8
+ Makit::Logging.default_logger.task_start("setup")
9
+ Makit::Setup::Runner.run
10
+ end
11
+ else
12
+ Makit::Logging.default_logger.debug("Project not configured, skipping setup task definition")
6
13
  end
@@ -1,11 +1,17 @@
1
- require_relative "../git/repository"
1
+ # frozen_string_literal: true
2
2
 
3
- if Makit::Git::Repository.git_repo?
3
+ require_relative "../git/cli"
4
+
5
+ if Dir.exist?(".git")
4
6
  desc "Sync changes with the git repository."
5
- task sync: %i[integrate pull_incoming] do
6
- Makit::TaskInfo.track(:sync) do
7
- # Makit::SHOW.task(:sync)
8
- Makit::Git::CLI.sync
9
- end
7
+ task :sync do
8
+ Makit::Logging.default_logger.task_start("sync")
9
+ # Makit::SHOW.task(:sync)
10
+ Makit::Git::CLI.sync
11
+ "git pull".try
12
+ "git push origin".try
13
+ "git push origin --tags".try
10
14
  end
15
+ else
16
+ Makit::Logging.default_logger.debug("Not a git repository, skipping sync")
11
17
  end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ if Dir.exist?(".git")
4
+ desc "tag the current version"
5
+ task :tag do
6
+ # check if the variable VERSION is defined
7
+ unless defined?(VERSION)
8
+ puts " VERSION is not defined".colorize(:red)
9
+ return
10
+ end
11
+
12
+ Makit::Git::CLI.tag(VERSION)
13
+ end
14
+ else
15
+ Makit::Logging.default_logger.debug("Not a git repository, skipping tag")
16
+ end
@@ -10,70 +10,72 @@
10
10
  require_relative "hook_manager"
11
11
 
12
12
  # Monkey patch Rake::Task to add hook support
13
- class Rake::Task
14
- # Store original methods before patching
15
- alias_method :original_invoke, :invoke
16
- alias_method :original_execute, :execute
13
+ module Rake
14
+ class Task
15
+ # Store original methods before patching
16
+ alias original_invoke invoke
17
+ alias original_execute execute
17
18
 
18
- # Enhanced invoke method with hook support
19
- #
20
- # This method wraps the original invoke method to execute pre and post hooks
21
- # around task execution. It handles errors gracefully and ensures hooks are
22
- # always executed even if the task fails.
23
- #
24
- # @param args [Array] arguments passed to the task
25
- # @return [Object] the result of the task execution
26
- def invoke(*args)
27
- start_time = Time.now
28
- result = nil
29
- error = nil
19
+ # Enhanced invoke method with hook support
20
+ #
21
+ # This method wraps the original invoke method to execute pre and post hooks
22
+ # around task execution. It handles errors gracefully and ensures hooks are
23
+ # always executed even if the task fails.
24
+ #
25
+ # @param args [Array] arguments passed to the task
26
+ # @return [Object] the result of the task execution
27
+ def invoke(*args)
28
+ start_time = Time.now
29
+ result = nil
30
+ error = nil
30
31
 
31
- begin
32
- # Execute pre-task hooks
33
- Makit::Tasks::HookManager.execute_pre_hooks(name)
32
+ begin
33
+ # Execute pre-task hooks
34
+ Makit::Tasks::HookManager.execute_pre_hooks(name)
34
35
 
35
- # Execute the original task
36
- result = original_invoke(*args)
37
- rescue => e
38
- error = e
39
- raise
40
- ensure
41
- # Execute post-task hooks (always runs, even on error)
42
- duration = Time.now - start_time
43
- Makit::Tasks::HookManager.execute_post_hooks(name, duration, result, error)
36
+ # Execute the original task
37
+ result = original_invoke(*args)
38
+ rescue StandardError => e
39
+ error = e
40
+ raise
41
+ ensure
42
+ # Execute post-task hooks (always runs, even on error)
43
+ duration = Time.now - start_time
44
+ Makit::Tasks::HookManager.execute_post_hooks(name, duration, result, error)
45
+ end
46
+
47
+ result
44
48
  end
45
49
 
46
- result
47
- end
50
+ # Enhanced execute method with hook support
51
+ #
52
+ # This method wraps the original execute method to execute pre and post hooks
53
+ # around task execution. It handles errors gracefully and ensures hooks are
54
+ # always executed even if the task fails.
55
+ #
56
+ # @param args [Array] arguments passed to the task
57
+ # @return [Object] the result of the task execution
58
+ def execute(*args)
59
+ start_time = Time.now
60
+ result = nil
61
+ error = nil
48
62
 
49
- # Enhanced execute method with hook support
50
- #
51
- # This method wraps the original execute method to execute pre and post hooks
52
- # around task execution. It handles errors gracefully and ensures hooks are
53
- # always executed even if the task fails.
54
- #
55
- # @param args [Array] arguments passed to the task
56
- # @return [Object] the result of the task execution
57
- def execute(*args)
58
- start_time = Time.now
59
- result = nil
60
- error = nil
63
+ begin
64
+ # Execute pre-task hooks
65
+ Makit::Tasks::HookManager.execute_pre_hooks(name)
61
66
 
62
- begin
63
- # Execute pre-task hooks
64
- Makit::Tasks::HookManager.execute_pre_hooks(name)
67
+ # Execute the original task
68
+ result = original_execute(*args)
69
+ rescue StandardError => e
70
+ error = e
71
+ raise
72
+ ensure
73
+ # Execute post-task hooks (always runs, even on error)
74
+ duration = Time.now - start_time
75
+ Makit::Tasks::HookManager.execute_post_hooks(name, duration, result, error)
76
+ end
65
77
 
66
- # Execute the original task
67
- result = original_execute(*args)
68
- rescue => e
69
- error = e
70
- raise
71
- ensure
72
- # Execute post-task hooks (always runs, even on error)
73
- duration = Time.now - start_time
74
- Makit::Tasks::HookManager.execute_post_hooks(name, duration, result, error)
78
+ result
75
79
  end
76
-
77
- result
78
80
  end
79
81
  end