In Files

  • minirake

RakeApp

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

Constants

OPTIONS
RAKEFILES

Public Class Methods

new() click to toggle source

Create a RakeApp object.

 
               # File minirake, line 333
def initialize
  @rakefile = nil
  @nosearch = false
end
            

Public Instance Methods

command_line_options() click to toggle source

Return a list of the command line options supported by the program.

 
               # File minirake, line 382
def command_line_options
  OPTIONS.collect { |lst| lst[0..-2] }
end
            
display_tasks() click to toggle source

Display the tasks and dependencies.

 
               # File minirake, line 373
def display_tasks
  MiniRake::Task.tasks.each do |t|
    puts "#{t.class} #{t.name}"
    t.prerequisites.each { |pre| puts "    #{pre}" }
  end
end
            
do_option(opt, value) click to toggle source

Do the option defined by opt and value.

 
               # File minirake, line 387
def do_option(opt, value)
  case opt
  when '--dry-run'
    $dryrun = true
    $trace = true
  when '--help'
    help
    exit
  when '--libdir'
    $:.push(value)
  when '--nosearch'
    @nosearch = true
  when '--quiet'
    $verbose = false
  when '--rakefile'
    RAKEFILES.clear
    RAKEFILES << value
  when '--require'
    require value
  when '--tasks'
    $show_tasks = true
  when '--pull-gems'
    $pull_gems = true
  when '--trace'
    $trace = true
  when '--usage'
    usage
    exit
  when '--verbose'
    $verbose = true
  when '--version'
    puts "rake, version #{RAKEVERSION}"
    exit
  when '--directory'
    Dir.chdir value
  else
    fail "Unknown option: #{opt}"
  end
end
            
handle_options() click to toggle source

Read and handle the command line options.

 
               # File minirake, line 428
def handle_options
  $verbose = false
  $pull_gems = false
  opts = GetoptLong.new(*command_line_options)
  opts.each { |opt, value| do_option(opt, value) }
end
            
have_rakefile() click to toggle source

True if one of the files in RAKEFILES is in the current directory. If a match is found, it is copied into @rakefile.

 
               # File minirake, line 340
def have_rakefile
  RAKEFILES.each do |fn|
    if File.exist?(fn)
      @rakefile = fn
      return true
    end
  end
  return false
end
            
help() click to toggle source

Display the rake command line help.

 
               # File minirake, line 356
def help
  usage
  puts
  puts "Options are ..."
  puts
  OPTIONS.sort.each do |long, short, mode, desc|
    if mode == GetoptLong::REQUIRED_ARGUMENT
      if desc =~ /\b([A-Z]{2,})\b/
        long = long + "=#{$1}"
      end
    end
    printf "  %-20s (%s)\n", long, short
    printf "      %s\n", desc
  end
end
            
run() click to toggle source

Run the rake application.

 
               # File minirake, line 436
def run
  handle_options
  begin
    here = Dir.pwd
    while ! have_rakefile
      Dir.chdir("..")
      if Dir.pwd == here || @nosearch
        fail "No Rakefile found (looking for: #{RAKEFILES.join(', ')})"
      end
      here = Dir.pwd
    end
    tasks = []
    ARGV.each do |task_name|
      if /^(\w+)=(.*)/.match(task_name)
        ENV[$1] = $2
      else
        tasks << task_name
      end
    end
    puts "(in #{Dir.pwd})"
    $rakefile = @rakefile
    load @rakefile
    if $show_tasks
      display_tasks
    else
      tasks.push("default") if tasks.size == 0
      tasks.each do |task_name|
        MiniRake::Task[task_name].invoke
      end
    end
  rescue Exception => ex
    puts "rake aborted!"
    puts ex.message
    if $trace
      puts ex.backtrace.join("\n")
    else
      puts ex.backtrace.find {|str| str =~ /#{@rakefile}/ } || ""
    end
    exit 1
  end
end
            
usage() click to toggle source

Display the program usage line.

 
               # File minirake, line 351
def usage
    puts "rake [-f rakefile] {options} targets..."
end
            

Commenting is here to help enhance the documentation. For example, code samples, or clarification of the documentation.

If you have questions about Ruby or the documentation, please post to one of the Ruby mailing lists. You will get better, faster, help that way.

If you wish to post a correction of the docs, please do so, but also file bug report so that it can be corrected for the next release. Thank you.

If you want to help improve the Ruby documentation, please visit Documenting-ruby.org.

blog comments powered by Disqus