Module: RakeCommander::Patcher::Application::TopLevelMethod::Patch

Includes:
Debug
Defined in:
lib/rake-commander/patcher/application/top_level_method.rb

Instance Method Summary collapse

Methods included from Debug

#rake_comm_debug, #rake_comm_debug_main_object_id, #rake_comm_debug_random_object_id

Instance Method Details

#top_levelObject

To preserve rake as main executable, as the RunMethod::Patch is applied only when Rake::Application requires the Rakefile that loads rake-commander, we need to:

  1. Intercept the execution on the next stage of the Rake::Application#run command, the top_level call, and re-launch the rake application (so it only receives the ARGV cut that the main patch provides)
  2. Ensure that re-launch is done only once.
  3. Ensure that it does exit(0) to the original running application.


35
36
37
38
39
40
41
42
43
44
# File 'lib/rake-commander/patcher/application/top_level_method.rb', line 35

def top_level
  unless @rake_commander_run_argv_patch
    @rake_commander_run_argv_patch = true
    RakeCommander.relaunch_rake_application
    # Should not reach this point
  end
  rake_comm_debug "T O P   L E V E L   ( p a t c h    a c t i v e )", "\n", num: 2, pid: true
  rake_comm_debug "  ---> Known tasks: #{tasks.map(&:name).join(", ")}"
  super
end