lib/tasks/seed.rake in seedbank-0.4.0 vs lib/tasks/seed.rake in seedbank-0.5.0.pre
- old
+ new
@@ -1,42 +1,38 @@
+# frozen_string_literal: true
namespace :db do
-
- include Seedbank::DSL
-
- base_dependencies = ['db:seed:original']
+ using Seedbank::DSL
override_dependency = ['db:seed:common']
namespace :seed do
# Create seed tasks for all the seeds in seeds_path and add them to the dependency
# list along with the original db/seeds.rb.
- common_dependencies = glob_seed_files_matching('*.seeds.rb').sort.map { |seed_file| seed_task_from_file(seed_file) }
+ common_dependencies = seed_tasks_matching(Seedbank.matcher)
- desc "Load the seed data from db/seeds.rb and db/seeds/*.seeds.rb."
- task 'common' => base_dependencies + common_dependencies
+ # Only add the original seeds if db/seeds.rb exists.
+ if original_seeds_file
+ define_seed_task original_seeds_file, :original
+ common_dependencies.unshift('db:seed:original')
+ end
+ desc "Load the seed data from db/seeds.rb and db/seeds/#{Seedbank.matcher}."
+ task 'common' => common_dependencies
+
# Glob through the directories under seeds_path and create a task for each adding it to the dependency list.
# Then create a task for the environment
glob_seed_files_matching('/*/').each do |directory|
environment = File.basename(directory)
- environment_dependencies = glob_seed_files_matching(environment, '*.seeds.rb').sort.map { |seed_file| seed_task_from_file(seed_file) }
+ environment_dependencies = seed_tasks_matching(environment, Seedbank.matcher)
- desc "Load the seed data from db/seeds.rb, db/seeds/*.seeds.rb and db/seeds/#{environment}/*.seeds.rb."
+ desc "Load the seed data from db/seeds.rb, db/seeds/#{Seedbank.matcher} and db/seeds/#{environment}/#{Seedbank.matcher}."
task environment => ['db:seed:common'] + environment_dependencies
override_dependency << "db:seed:#{environment}" if defined?(Rails) && Rails.env == environment
end
-
- if Rails.version > '4'
- original_seeds_file = Rails.application.paths["db/seeds.rb"].existent.first
- elsif Rails.version > '3.1'
- original_seeds_file = Rails.application.paths["db/seeds"].existent.first
- else
- original_seeds_file = Rails.root.join("db","seeds").children.first.to_s
- end
- define_seed_task original_seeds_file, :original if original_seeds_file
end
# Override db:seed to run all the common and environments seeds plus the original db:seed.
- desc 'Load the seed data from db/seeds.rb, db/seeds/*.seeds.rb and db/seeds/ENVIRONMENT/*.seeds.rb. ENVIRONMENT is the current environment in Rails.env.'
- override_seed_task :seed => override_dependency
+ desc %(Load the seed data from db/seeds.rb, db/seeds/#{Seedbank.matcher} and db/seeds/ENVIRONMENT/#{Seedbank.matcher}.
+ ENVIRONMENT is the current Rails.env.)
+ override_seed_task seed: override_dependency
end