<commit_before>=begin
require 'fileutils'

namespace :dynamic_forms do
  task :uninstall do 
    RAILS_ROOT = File.join(File.dirname(__FILE__), '..', '..', '..', '..')
    
    # delete files from /app that exist in plugin
    %w{controllers helpers models views}.each do |dir|
      dir_path = File.join(File.dirname(__FILE__), '..', 'lib', dir)
      Dir.foreach(dir_path) do |filename|
        next if filename =~ /^\./
        dest_path = File.join(RAILS_ROOT, 'app', dir, filename)
        next unless File.exist?(dest_path)
        FileUtils.rm_rf(dest_path)
      end
    end
    
    def gsub_file(path, regexp, *args, &block)
      content = File.read(path).gsub(regexp, *args, &block)
      File.open(path, 'wb') { |file| file.write(content) }
    end
    
    sentinel = <<-EOF
  map.resources :forms, :collection => {:preview => :post} do |f|
    f.resources :form_submissions
  end
EOF

    # Remove routes from the routes.rb file
    gsub_file(File.join(RAILS_ROOT, 'config', 'routes.rb'), /(#{Regexp.escape(sentinel)})/mi, '')
    
  end
end
=end<commit_msg>updated the uninstall task to remove the generated models<commit_after>require 'fileutils'

namespace :dynamic_forms do
  def remove_files(templates_path, app_path)
    Dir.foreach(templates_path) do |filename|
      next if filename =~ /^\./
      dest_path = File.join(app_path, filename)
      next unless File.exist?(dest_path)
      FileUtils.rm_rf(dest_path)
    end
  end
  
  task :uninstall do 
    RAILS_ROOT = File.join(File.dirname(__FILE__), '..', '..', '..', '..')
    
    # delete the generated models
    templates_path = File.join(File.dirname(__FILE__), '..', 'generators', 'dynamic_forms', 'templates', 'models')
    app_path = File.join(RAILS_ROOT, 'app', 'models')
    remove_files(templates_path, app_path)
    
    templates_path = File.join(File.dirname(__FILE__), '..', 'generators', 'dynamic_forms', 'templates', 'models', 'form_field')
    app_path = File.join(RAILS_ROOT, 'app', 'models', 'form_field')
    remove_files(templates_path, app_path)
  end
end
{'fraction_non_alphanumeric': 0.15021876519202723, 'fraction_numerical': 0.0, 'mean_word_length': 3.360169491525424, 'pattern_counts': {'":': 0, '<': 5, '<?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': '2099464', 'n_tokens_mistral': 703, 'n_tokens_neox': 697, 'n_words': 153}