<commit_before>namespace :scaffolder do
  
  # color goodness from http://snippets.dzone.com/posts/show/6693
  $terminal = %x(echo $TERM).strip!

  def puts_in_color(text, options = {})
    if $terminal == 'xterm-color'
      case options[:color]
      when :red
        puts "\033[31m#{text}\033[0m"
      when :green
        puts "\033[32m#{text}\033[0m"
      else
        puts text
      end
    else
      puts text
    end
  end

  def green(text)
    puts_in_color text, :color => :green
  end

  def red(text)
    puts_in_color text, :color => :red
  end

  desc "Set up config dir"
  task :install => :environment do
    config_dir = File.expand_path('config/scaffolder', Rails.root)
    mkdir config_dir unless File.exists? config_dir
    source_file = File.expand_path('../../../config/scaffolder/model.yml', __FILE__)
    dest_file = File.expand_path('model.yml', config_dir)
    copy_file source_file, dest_file
  end
  
  desc "Generate scaffolds from model input"
  task [:generate, :model, :command, :destroy] => :environment do |t, args|
    model_file = args[:model].blank? ? 'model' : args[:model]
    scaffold_command = args[:command].blank? ? 'scaffold' : args[:command]
    destroy = args[:destroy].blank? ? false : (args[:command] != 'false')

    models = YAML.load_file(File.expand_path('config/scaffolder/%s.yml' % model_file, Rails.root))
    models.each do |modelname, fields|

      if destroy
        command = "rails destroy %s %s\n" % [scaffold_command, modelname]
        puts "Running:"
        red command
        system(command)
      end

      # assemble the scaffold command
      fieldstring = ''
      if !fields.nil?
        if fields[0]['field'].nil?
          # supporting shorter syntax
          fields.each do |field|
            value = field.collect { |field, type| " %s:%s" % [field, type] }[0]
            fieldstring << value.to_s
          end
        else<commit_msg>syntax is t :name, [:args] => [:deps], previously lumped name into args<commit_after>namespace :scaffolder do
  
  # color goodness from http://snippets.dzone.com/posts/show/6693
  $terminal = %x(echo $TERM).strip!

  def puts_in_color(text, options = {})
    if $terminal == 'xterm-color'
      case options[:color]
      when :red
        puts "\033[31m#{text}\033[0m"
      when :green
        puts "\033[32m#{text}\033[0m"
      else
        puts text
      end
    else
      puts text
    end
  end

  def green(text)
    puts_in_color text, :color => :green
  end

  def red(text)
    puts_in_color text, :color => :red
  end

  desc "Set up config dir"
  task :install => :environment do
    config_dir = File.expand_path('config/scaffolder', Rails.root)
    mkdir config_dir unless File.exists? config_dir
    source_file = File.expand_path('../../../config/scaffolder/model.yml', __FILE__)
    dest_file = File.expand_path('model.yml', config_dir)
    copy_file source_file, dest_file
  end
  
  desc "Generate scaffolds from model input"
  task :generate, [:model, :command, :destroy] => :environment do |t, args|
    model_file = args[:model].blank? ? 'model' : args[:model]
    scaffold_command = args[:command].blank? ? 'scaffold' : args[:command]
    destroy = args[:destroy].blank? ? false : (args[:command] != 'false')

    models = YAML.load_file(File.expand_path('config/scaffolder/%s.yml' % model_file, Rails.root))
    models.each do |modelname, fields|

      if destroy
        command = "rails destroy %s %s\n" % [scaffold_command, modelname]
        puts "Running:"
        red command
        system(command)
      end

      # assemble the scaffold command
      fieldstring = ''
      if !fields.nil?
        if fields[0]['field'].nil?
          # supporting shorter syntax
          fields.each do |field|
            value = field.collect { |field, type| " %s:%s" % [field, type] }[0]
            fieldstring << value.to_s
          end
        else
{'fraction_non_alphanumeric': 0.13102564102564102, 'fraction_numerical': 0.012307692307692308, 'mean_word_length': 2.6594746716697935, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 12, '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': '3689977', 'n_tokens_mistral': 1309, 'n_tokens_neox': 1257, 'n_words': 317}