diff --git a/lib/seedbank/dsl.rb b/lib/seedbank/dsl.rb index 4ef9d80..30f6210 100644 --- a/lib/seedbank/dsl.rb +++ b/lib/seedbank/dsl.rb @@ -11,9 +11,12 @@ def override_seed_task(*args) end def seed_tasks_matching(*pattern) - glob_seed_files_matching(*pattern) + tasks = glob_seed_files_matching(*pattern) .sort .map { |seed_file| seed_task_from_file(seed_file) } + + # binding.pry + tasks end def seed_task_from_file(seed_file) @@ -21,14 +24,19 @@ def seed_task_from_file(seed_file) suffix = Seedbank.matcher.gsub(/\A\*/, '') fq_name = scopes.push(File.basename(seed_file, suffix)).join(':') - define_seed_task(seed_file, fq_name) + task_name = define_seed_task(seed_file, fq_name) + # binding.pry + task_name end def glob_seed_files_matching(*args, &block) - Dir.glob(File.join(seeds_root, *args), &block) + files = Dir.glob(File.join(seeds_root, *args), &block) + # binding.pry + files end def define_seed_task(seed_file, *args) + # binding.pry task = Rake::Task.define_task(*args) do |seed_task| runner.evaluate(seed_task, seed_file) if File.exist?(seed_file) end @@ -37,6 +45,7 @@ def define_seed_task(seed_file, *args) task.add_description "Load the seed data from #{relative_file}" add_environment_dependency(task) + # binding.pry task.name end diff --git a/lib/seedbank/runner.rb b/lib/seedbank/runner.rb index c452363..909c6f7 100644 --- a/lib/seedbank/runner.rb +++ b/lib/seedbank/runner.rb @@ -49,6 +49,9 @@ def let!(name, &block) def evaluate(seed_task, seed_file) @_seed_task = seed_task instance_eval(File.read(seed_file), seed_file) + rescue Errno::EISDIR => e + binding.pry + raise e end end end diff --git a/lib/tasks/seed.rake b/lib/tasks/seed.rake index 1d36e79..0249229 100644 --- a/lib/tasks/seed.rake +++ b/lib/tasks/seed.rake @@ -10,6 +10,7 @@ namespace :db 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 = seed_tasks_matching(Seedbank.matcher) + # binding.pry # Only add the original seeds if db/seeds.rb exists. if original_seeds_file @@ -22,7 +23,9 @@ namespace :db do # 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 + # binding.pry glob_seed_files_matching('/*/').each do |directory| + # binding.pry environment = File.basename(directory) environment_dependencies = seed_tasks_matching(environment, Seedbank.matcher) @@ -34,6 +37,8 @@ namespace :db do end end + # binding.pry + # 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/#{Seedbank.matcher} and db/seeds/ENVIRONMENT/#{Seedbank.matcher}. ENVIRONMENT is the current Rails.env.)