Skip to content

Commit

Permalink
tmp for debug
Browse files Browse the repository at this point in the history
  • Loading branch information
nard-tech committed Apr 28, 2018
1 parent c63e24d commit fec03ce
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
15 changes: 12 additions & 3 deletions lib/seedbank/dsl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,32 @@ 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)
scopes = scope_from_seed_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
Expand All @@ -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

Expand Down
3 changes: 3 additions & 0 deletions lib/seedbank/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 5 additions & 0 deletions lib/tasks/seed.rake
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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.)
Expand Down

0 comments on commit fec03ce

Please sign in to comment.