In Files

  • rake-13.0.3/lib/rake/application.rb

Rake::Application

Rake main application object. When invoking rake from the command line, a Rake::Application object is created and run.

Constants

DEFAULT_RAKEFILES

Attributes

name[R]

The name of the application (typically 'rake')

original_dir[R]

The original directory where rake was invoked.

rakefile[R]

Name of the actual rakefile used.

terminal_columns[RW]

Number of columns on the terminal

top_level_tasks[R]

List of the top level task names (task names from the command line).

tty_output[W]

Override the detected TTY output state (mostly for testing)

Public Class Methods

new() click to toggle source

Initialize a Rake::Application object.

 
               # File rake-13.0.3/lib/rake/application.rb, line 48
def initialize
  super
  @name = "rake"
  @rakefiles = DEFAULT_RAKEFILES.dup
  @rakefile = nil
  @pending_imports = []
  @imported = []
  @loaders = {}
  @default_loader = Rake::DefaultLoader.new
  @original_dir = Dir.pwd
  @top_level_tasks = []
  add_loader("rb", DefaultLoader.new)
  add_loader("rf", DefaultLoader.new)
  add_loader("rake", DefaultLoader.new)
  @tty_output = STDOUT.tty?
  @terminal_columns = ENV["RAKE_COLUMNS"].to_i

  set_default_options
end
            

Public Instance Methods

add_loader(ext, loader) click to toggle source

Add a loader to handle imported files ending in the extension ext.

 
               # File rake-13.0.3/lib/rake/application.rb, line 138
def add_loader(ext, loader)
  ext = ".#{ext}" unless ext =~ /^\./
  @loaders[ext] = loader
end
            
init(app_name="rake", argv = ARGV) click to toggle source

Initialize the command line parameters and app name.

 
               # File rake-13.0.3/lib/rake/application.rb, line 87
def init(app_name="rake", argv = ARGV)
  standard_exception_handling do
    @name = app_name
    begin
      args = handle_options argv
    rescue ArgumentError
      # Backward compatibility for capistrano
      args = handle_options
    end
    collect_command_line_tasks(args)
  end
end
            
load_rakefile() click to toggle source

Find the rakefile and then load it and any pending imports.

 
               # File rake-13.0.3/lib/rake/application.rb, line 101
def load_rakefile
  standard_exception_handling do
    raw_load_rakefile
  end
end
            
options() click to toggle source

Application options from the command line

 
               # File rake-13.0.3/lib/rake/application.rb, line 144
def options
  @options ||= OpenStruct.new
end
            
run(argv = ARGV) click to toggle source

Run the Rake application. The run method performs the following three steps:

  • Initialize the command line options (init).

  • Define the tasks (load_rakefile).

  • Run the top level tasks (top_level).

If you wish to build a custom rake command, you should call init on your application. Then define any tasks. Finally, call top_level to run your top level tasks.

 
               # File rake-13.0.3/lib/rake/application.rb, line 78
def run(argv = ARGV)
  standard_exception_handling do
    init "rake", argv
    load_rakefile
    top_level
  end
end
            
run_with_threads() click to toggle source

Run the given block with the thread startup and shutdown.

 
               # File rake-13.0.3/lib/rake/application.rb, line 121
def run_with_threads
  thread_pool.gather_history if options.job_stats == :history

  yield

  thread_pool.join
  if options.job_stats
    stats = thread_pool.statistics
    puts "Maximum active threads: #{stats[:max_active_threads]} + main"
    puts "Total threads in play:  #{stats[:total_threads_in_play]} + main"
  end
  ThreadHistoryDisplay.new(thread_pool.history).show if
    options.job_stats == :history
end
            
top_level() click to toggle source

Run the top level tasks of a Rake application.

 
               # File rake-13.0.3/lib/rake/application.rb, line 108
def top_level
  run_with_threads do
    if options.show_tasks
      display_tasks_and_comments
    elsif options.show_prereqs
      display_prerequisites
    else
      top_level_tasks.each { |task_name| invoke_task(task_name) }
    end
  end
end