<commit_before>require 'rails'
class SeedBed
  @@debug = true
  attr_accessor :path
  
  def plant( file )
    @path = "db/seeds"
    # load File.expand_path("#{@path}/../../Rakefile")
    yield self if block_given?
    expanded_path = File.expand_path("#{@path}/#{file.to_s}.rb")
    puts "Growing #{expanded_path}" if SeedBed.debug
    require expanded_path
    
  end
  
  def self.message( msg )
    puts ""
    puts "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-="
    puts msg
    puts ""
    puts "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-="
  end
  
  def self.debug=(d)
    @@debug = d
  end
  
  def self.debug
    @@debug
  end
  
  def self.available_seeds
    @path = "db/seeds"
    basedir = File.join( File.expand_path(@path), "**" , "*.rb")
    files = Dir.glob( basedir ).collect{|d| d.split( File.expand_path(@path) ).last.split('/')[1..-1].collect{|s| s.split('.rb').first.to_sym} }
    namespaces = Hash.new{ |h,k| h[k] = Hash.new &h.default_proc }
    files.each do |path|
      sub = namespaces
      path.each{ |dir| sub[dir]; sub = sub[dir] }
    end
    namespaces
  end
  
  def self.tasks
    build_tree( SeedBed.available_seeds )
  end
  
  private 
  
  def self.build_tree(b)
    fil = ""
    b.keys.each do |t|
      fil << "desc \"plants seeds for #{t}\" \n"
      if b[t].empty?
      fil << "task :#{t} => :environment do |tsk| \n"
        fil << "puts tsk.scope[2..-1].join('/') \n"
        fil << "SeedBed.plant( tsk.scope[2..-1].join('/') + '/' + '#{t}' )\n"
      fil << "end \n"
      else
        fil << "namespace :#{t} do \n"
          fil << build_tree( b[t]  )
          fil << "\n"
        fil << "end \n"
      end
    end
    fil
    # branch.keys.reject{|k| branch[k].empty? }.each do |ns|
    #   namespace ns do 
    #     branch[ns].keys.each do |t|
    #       desc "Runs seed for #{t}"<commit_msg>Adds the ability to have an overlapping task and namespace per christianschulze<commit_after>require 'rails'
class SeedBed
  @@debug = true
  attr_accessor :path
  
  def plant( file )
    @path = "db/seeds"
    # load File.expand_path("#{@path}/../../Rakefile")
    yield self if block_given?
    expanded_path = File.expand_path("#{@path}/#{file.to_s}.rb")
    puts "Growing #{expanded_path}" if SeedBed.debug
    require expanded_path
    
  end
  
  def self.message( msg )
    puts ""
    puts "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-="
    puts msg
    puts ""
    puts "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-="
  end
  
  def self.debug=(d)
    @@debug = d
  end
  
  def self.debug
    @@debug
  end
  
  def self.available_seeds
    @path = "db/seeds"
    basedir = File.join( File.expand_path(@path), "**" , "*.rb")
    files = Dir.glob( basedir ).collect{|d| d.split( File.expand_path(@path) ).last.split('/')[1..-1].collect{|s| s.split('.rb').first.to_sym} }
    namespaces = Hash.new{ |h,k| h[k] = Hash.new &h.default_proc }
    files.each do |path|
      sub = namespaces
      path.each{ |dir| sub[dir]; sub = sub[dir] }
    end
    namespaces
  end
  
  def self.tasks
    build_tree( SeedBed.available_seeds )
  end
  
  private 
  
  def self.build_tree(b)
    fil = ""
    b.keys.each do |t|
      fil << "desc \"plants seeds for #{t}\" \n"
      
      fil << "task :#{t} => :environment do |tsk| \n"
        fil << "puts tsk.scope[2..-1].join('/') \n"
        fil << "SeedBed.plant( tsk.scope[2..-1].join('/') + '/' + '#{t}' )\n"
      fil << "end \n"
      unless b[t].empty?
        fil << "namespace :#{t} do \n"
          fil << build_tree( b[t]  )
          fil << "\n"
        fil << "end \n"
      end
    end
    fil
    # branch.keys.reject{|k| branch[k].empty? }.each do |ns|
    #   namespace ns do 
    #     branch[ns].keys.each do |t|
    #       desc "Runs seed for #{t}"
{'fraction_non_alphanumeric': 0.21195942338494395, 'fraction_numerical': 0.003203416978109984, 'mean_word_length': 2.0562805872756935, 'pattern_counts': {'":': 0, '<': 39, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5581068', 'n_tokens_mistral': 1467, 'n_tokens_neox': 1409, 'n_words': 321}