Skip to content
This repository has been archived by the owner on Feb 5, 2019. It is now read-only.

Commit

Permalink
Custom bot Rake tasks.
Browse files Browse the repository at this point in the history
  • Loading branch information
Dale Campbell committed Jun 29, 2008
1 parent ae1786e commit 6d750e1
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 12 deletions.
35 changes: 23 additions & 12 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,22 @@ namespace :app do
task :start do
system 'script/daemon start'
end

desc "Stop the Autumn daemon"
task :stop do
system 'script/daemon stop'
end

desc "Restart the Autumn daemon"
task :restart do
system 'script/daemon restart'
end

desc "Start Autumn but not as a daemon (stay on top)"
task :run do
system 'script/daemon run'
end

desc "Force the daemon to a stopped state (clears PID files)"
task :zap do
system 'script/daemon zap'
Expand Down Expand Up @@ -86,7 +86,7 @@ namespace :db do
raise "No databases configured" unless File.exist? "config/seasons/#{@genesis.config.global :season}/database.yml"
db = DataMapper::Database[leaf.database_name]
raise "No database configured for #{lname}" unless db

case db.adapter.class.to_s
when 'DataMapper::Adapters::MysqlAdapter'
`echo "CREATE DATABASE #{db.database} CHARACTER SET utf8" | mysql -u#{db.username} -h#{db.host} -p#{db.password}`
Expand All @@ -96,7 +96,7 @@ namespace :db do
`sqlite3 "#{db.database}"`
end
end

desc "Drop a database"
task :drop => :full_bootstrap do
lname = ENV['LEAF']
Expand All @@ -105,7 +105,7 @@ namespace :db do
raise "No databases configured" unless File.exist? "config/seasons/#{@genesis.config.global :season}/database.yml"
db = DataMapper::Database[leaf.database_name]
raise "No database configured for #{lname}" unless db

case db.adapter.class.to_s
when 'DataMapper::Adapters::MysqlAdapter'
`echo "DROP DATABASE #{db.database}" | mysql -u#{db.username} -h#{db.host} -p#{db.password}`
Expand All @@ -115,13 +115,13 @@ namespace :db do
FileUtils.rm_f db.database
end
end

desc "Create database tables according to the model objects"
task :populate => :full_bootstrap do
lname = ENV['LEAF']
raise "Usage: LEAF=[Leaf name] rake db:populate" unless lname
raise "Unknown leaf #{lname}" unless leaf = Autumn::Foliater.instance.leaves[lname]

leaf.database do
Dir.glob("support/#{leaf.class.pathize}/**/*.rb").each do |file|
content = nil
Expand All @@ -135,7 +135,7 @@ namespace :db do
end
end
end

desc "Drop, recreates, and repopulates a database"
task :reset => [ 'db:drop', 'db:create', 'db:populate' ]
end
Expand All @@ -146,16 +146,27 @@ namespace :doc do
system 'rm -rf doc/api' if File.directory? 'doc/api'
system "rdoc --main README --title 'Autumn API Documentation' -o doc/api --line-numbers --inline-source libs README"
end

desc "Generate documentation for all leaves"
task :leaves => [ :environment, :clear ] do
system 'rm -rf doc/leaves' if File.directory? 'doc/leaves'
system "rdoc --main README --title 'Autumn Leaves Documentation' -o doc/leaves --line-numbers --inline-source leaves support"
end

desc "Remove all documentation"
task :clear => :environment do
system 'rm -rf doc/api' if File.directory? 'doc/api'
system 'rm -rf doc/leaves' if File.directory? 'doc/leaves'
end
end

# Load any custom Rake tasks in the bot's 'support/<bot_name>/tasks' directory.
FileList["leaves/*.rb"].each do |leaf|
leaf_name = leaf.split('/').last # Grab filename from the full path
leaf_name.slice!(-3, 3).downcase! # and remove '.rb'
namespace leaf_name.to_sym do # to create a nice namespace.
FileList["support/#{leaf_name}/tasks/**/*.rake"].sort.each do |task|
load task
end
end
end
4 changes: 4 additions & 0 deletions support/scorekeeper/tasks/stats.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
desc "Display Scorekeeper's stats"
task :stats do
puts 'Not yet implemented.'
end

0 comments on commit 6d750e1

Please sign in to comment.