Module: Lazyportal::CLI

Defined in:
lib/lazyportal/cli.rb

Instance Method Summary collapse

Instance Method Details

#generate_rakefileObject



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/lazyportal/cli.rb', line 3

def generate_rakefile

  # Rakefile contents includes the Tasks
  # module and loads tasks
  tasks = %{
require 'rubygems'
require 'lazyportal'

include Lazyportal::Tasks

Lazyportal::Tasks.load_tasks
  }
  
  # Check for existing Rakefile
  existing_rakefile = Dir["*"].select do |f| 
    f.match /rakefile/i
  end.first
    
  # Use existing Rakefile if one exists
  rakefile = existing_rakefile.nil? ? "Rakefile" : existing_rakefile
  
  # Append contents to existing Rakefile
  # or generate a new Rakefile
  create_file rakefile, tasks, :noclobber => true
  
  # Print message to tell the user what happened
  if existing_rakefile.nil?
    puts "lazy generated a new Rakefile"
    puts "type rake -T to see available tasks"
  else
    puts "lazy tasks were appended to existing Rakefile"
  end
end