#242 Thor
Nov 29, 2010 | 8 minutes | Tools
Thor is an alternative to Rake. It has better support for command line arguments and provides a way to add global scripts.
- Download:
- source codeProject Files in Zip (96.5 KB)
- mp4Full Size H.264 Video (13.2 MB)
- m4vSmaller H.264 Video (9.11 MB)
- webmFull Size VP8 Video (25 MB)
- ogvFull Size Theora Video (18.1 MB)
Resources
bash
thor help
thor list
thor setup:config
thor setup:config --force
thor setup:config private.yml --force
thor install lib/tasks/setup.thor
thor setup:populate
thor setup:populate --count 5
thor help thor list thor setup:config thor setup:config --force thor setup:config private.yml --force thor install lib/tasks/setup.thor thor setup:populate thor setup:populate --count 5
ruby
class Setup < Thor
desc "config [NAME]", "copy configuration files"
method_options :force => :boolean
def config(name = "*")
Dir["config/examples/#{name}"].each do |source|
destination = "config/#{File.basename(source)}"
FileUtils.rm(destination) if options[:force] && File.exist?(destination)
if File.exist?(destination)
puts "Skipping #{destination} because it already exists"
else
puts "Generating #{destination}"
FileUtils.cp(source, destination)
end
end
end
desc "populate", "generate records"
method_options :count => 10
def populate
require File.expand_path('config/environment.rb')
options[:count].times do |num|
puts "Generating article #{num}"
Article.create!(:name => "Article #{num}")
end
end
end
class Setup < Thor desc "config [NAME]", "copy configuration files" method_options :force => :boolean def config(name = "*") Dir["config/examples/#{name}"].each do |source| destination = "config/#{File.basename(source)}" FileUtils.rm(destination) if options[:force] && File.exist?(destination) if File.exist?(destination) puts "Skipping #{destination} because it already exists" else puts "Generating #{destination}" FileUtils.cp(source, destination) end end end desc "populate", "generate records" method_options :count => 10 def populate require File.expand_path('config/environment.rb') options[:count].times do |num| puts "Generating article #{num}" Article.create!(:name => "Article #{num}") end end end

