<commit_before># Mostly pinched from http://github.com/ryanb/nifty-generators/tree/master

Rails::Generator::Commands::Base.class_eval do
  def file_contains?(relative_destination, line)
    File.read(destination_path(relative_destination)).include?(line)
  end
end

Rails::Generator::Commands::Create.class_eval do
  def insert_before(file, line, stop='^(class|module) .+$')
    logger.insert "#{line} into #{file}"
    unless options[:pretend] || file_contains?(file, line)
      gsub_file file, /^#{stop}/ do |match|
        "#{line}\n#{match}"
      end
    end
  end
  
  def insert_after(file, line, stop='(class|module)')
    logger.insert "#{line} into #{file}"
    unless options[:pretend] || file_contains?(file, line)
      gsub_file file, /#{stop}/ do |match|
        "#{match}\n  #{line}"
      end
    end
  end
  
  def append(file, line)
    logger.insert "#{line} at end of #{file}"
    unless options[:pretend] || file_contains?(file, line)
      File.open(file, "a") do |file|
        file.write("\n" + line)
      end
    end
  end
  
end

Rails::Generator::Commands::Destroy.class_eval do
  def insert_before(file, line, stop='')
    logger.remove "#{line} from #{file}"
    unless options[:pretend]
      gsub_file file, "\n  #{line}", ''
    end
  end

  def insert_after(file, line, stop='')
    logger.remove "#{line} from #{file}"
    unless options[:pretend]
      gsub_file file, "\n  #{line}", ''
    end
  end
  
  def append(file, line)
    logger.insert "#{line} at end of #{file}"
  end

end

Rails::Generator::Commands::List.class_eval do
  def insert_before(file, line, stop='')
    logger.insert "#{line} into #{file}"
  end
  
  def insert_after(file, line, stop='')
    logger.insert "#{line} into #{file}"
  end
  
  def append(file, line)
    logger.insert "#{line} at end of #{file}"
  end
  
end<commit_msg>message tweak<commit_after># Mostly pinched from http://github.com/ryanb/nifty-generators/tree/master

Rails::Generator::Commands::Base.class_eval do
  def file_contains?(relative_destination, line)
    File.read(destination_path(relative_destination)).include?(line)
  end
end

Rails::Generator::Commands::Create.class_eval do
  def insert_before(file, line, stop='^(class|module) .+$')
    logger.insert "#{line} into #{file}"
    unless options[:pretend] || file_contains?(file, line)
      gsub_file file, /^#{stop}/ do |match|
        "#{line}\n#{match}"
      end
    end
  end
  
  def insert_after(file, line, stop='(class|module)')
    logger.insert "#{line} into #{file}"
    unless options[:pretend] || file_contains?(file, line)
      gsub_file file, /#{stop}/ do |match|
        "#{match}\n  #{line}"
      end
    end
  end
  
  def append(file, line)
    logger.insert "added legacy adapter to end of database.yml"
    unless options[:pretend] || file_contains?(file, line)
      File.open(file, "a") do |file|
        file.write("\n" + line)
      end
    end
  end
  
end

Rails::Generator::Commands::Destroy.class_eval do
  def insert_before(file, line, stop='')
    logger.remove "#{line} from #{file}"
    unless options[:pretend]
      gsub_file file, "\n  #{line}", ''
    end
  end

  def insert_after(file, line, stop='')
    logger.remove "#{line} from #{file}"
    unless options[:pretend]
      gsub_file file, "\n  #{line}", ''
    end
  end
  
  def append(file, line)
    logger.insert "added legacy adapter to end of database.yml"
  end

end

Rails::Generator::Commands::List.class_eval do
  def insert_before(file, line, stop='')
    logger.insert "#{line} into #{file}"
  end
  
  def insert_after(file, line, stop='')
    logger.insert "#{line} into #{file}"
  end
  
  def append(file, line)
    logger.insert "added legacy adapter to end of database.yml"
  end
  
end
{'fraction_non_alphanumeric': 0.15538379530916843, 'fraction_numerical': 0.0, 'mean_word_length': 3.410105757931845, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '5922723', 'n_tokens_mistral': 1265, 'n_tokens_neox': 1286, 'n_words': 320}