lib/seedbank/dsl.rb in seedbank-0.2.1 vs lib/seedbank/dsl.rb in seedbank-0.3.0.pre
- old
+ new
@@ -1,33 +1,38 @@
module Seedbank
module DSL
- def self.included(base)
- Rake::Task.send(:include, Seedbank::RenameTask)
- Rake::Application.send(:include, Seedbank::TaskManager)
+ def override_seed_task(*args)
+ task_name, arg_names, deps = Rake.application.resolve_args(args)
+ seed_task = Rake::Task.task_defined?(task_name) ? Rake::Task[task_name].clear : Rake::Task.define_task(task_name)
+ seed_task.send :instance_variable_set, '@full_comment', Rake.application.last_description
+ seed_task.enhance deps
end
- def override_seed_task(*args, &block)
- Rake.application.override_task(*args, &block)
- end
-
def seed_task_from_file(seed_file)
scopes = scope_from_seed_file(seed_file)
fq_name = scopes.push(File.basename(seed_file, '.seeds.rb')).join(':')
- args = Rake::Task.task_defined?('db:abort_if_pending_migrations') ? { fq_name => 'db:abort_if_pending_migrations' } : { fq_name => :environment }
- define_seed_task(seed_file, args)
+ define_seed_task(seed_file, fq_name)
end
def glob_seed_files_matching(*args, &block)
Dir.glob(File.join(seeds_root, *args), &block)
end
def define_seed_task(seed_file, *args)
task = Rake::Task.define_task(*args) do |seed_task|
Seedbank::Runner.new(seed_task).module_eval(File.read(seed_file), seed_file) if File.exist?(seed_file)
end
+
task.add_description "Load the seed data from #{seed_file}"
+
+ if Rake::Task.task_defined?('db:abort_if_pending_migrations')
+ task.enhance(['db:abort_if_pending_migrations'])
+ elsif Rake::Task.task_defined?(':environment')
+ task.enhance([':environment'])
+ end
+
task.name
end
def scope_from_seed_file(seed_file)
dirname = Pathname.new(seed_file).dirname