Created
February 19, 2009 01:43
-
-
Save TheNicholasNick/66669 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'rake/rdoctask' | |
require 'merb-core' | |
require 'merb-core/tasks/merb' | |
include FileUtils | |
# Load the basic runtime dependencies; this will include | |
# any plugins and therefore plugin rake tasks. | |
init_env = ENV['MERB_ENV'] || 'rake' | |
Merb.load_dependencies(:environment => init_env) | |
# Get Merb plugins and dependencies | |
Merb::Plugins.rakefiles.each { |r| require r } | |
# Load any app level custom rakefile extensions from lib/tasks | |
tasks_path = File.join(File.dirname(__FILE__), "lib", "tasks") | |
rake_files = Dir["#{tasks_path}/*.rake"] | |
rake_files.each{|rake_file| load rake_file } | |
desc "Start runner environment" | |
task :merb_env do | |
Merb.start_environment(:environment => init_env, :adapter => 'runner') | |
end | |
require 'spec/rake/spectask' | |
require 'merb-core/test/tasks/spectasks' | |
desc 'Default: run spec examples' | |
task :default => 'spec' | |
############################################################################## | |
# ADD YOUR CUSTOM TASKS IN /lib/tasks | |
# NAME YOUR RAKE FILES file_name.rake | |
############################################################################## | |
def insert_fixture(fixture_filename, opts={}) | |
basename = File.basename(fixture_filename, '.yaml') | |
model = Kernel::const_get(basename.camel_case) | |
template = Erubis::Eruby.new(File.read(fixture_filename)).result(binding()) | |
fixture = YAML::load(template) | |
# this will raise an exception if the fixture insertion fails | |
opts[:graceful] ||= false | |
fixture.each do |attributes| | |
m = model.new(attributes) | |
if opts[:graceful] | |
m.save | |
else | |
raise unless m.save | |
end | |
end | |
end | |
namespace :db do | |
namespace :fixtures do | |
desc 'insert postcode/suburb info into database' | |
task :postcodes => [:merb_env] do | |
insert_fixture('spec/fixtures/postcode.yaml') | |
insert_fixture('spec/fixtures/suburb.yaml', :graceful => true) | |
end | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment