<commit_before>require 'fileutils'

class Admin::Project < ActiveRecord::Base
  set_table_name "admin_projects"
  
  belongs_to :user

  belongs_to :maven_jnlp_server, :class_name => "MavenJnlp::MavenJnlpServer"
  belongs_to :maven_jnlp_family, :class_name => "MavenJnlp::MavenJnlpFamily"

  serialize :states_and_provinces
 
  acts_as_replicatable
  
  include Changeable
  
  self.extend SearchableModel
  
  @@searchable_attributes = %w{name description}

  def before_save
    if snapshot_enabled
      self.jnlp_version_str = maven_jnlp_family.snapshot_version
    end
  end
  
  def after_save
    if name == APP_CONFIG[:site_name] && url == APP_CONFIG[:site_url]
      write_to_settings_yml
    end
    if self.enable_default_users
      User.unsuspend_default_users
    else
      User.suspend_default_users
    end
  end

  def write_to_settings_yml
    new_settings = generate_settings_yml
    FileUtils.copy("#{RAILS_ROOT}/config/settings.yml", "#{RAILS_ROOT}/config/settings-backup.yml")
    File.open("#{RAILS_ROOT}/config/settings.yml", 'w') do |f|
      f.write new_settings
    end
  end

  def generate_settings_yml
    app_config = YAML.load_file("#{RAILS_ROOT}/config/settings.yml")
    app_config[RAILS_ENV]['site_name'] = self.name
    app_config[RAILS_ENV]['site_url'] = self.url
    app_config[RAILS_ENV]['enable_default_users'] = self.enable_default_users
    app_config[RAILS_ENV]['description'] = self.description
    app_config[RAILS_ENV]['states_and_provinces'] = self.states_and_provinces
    app_config[RAILS_ENV]['default_maven_jnlp_server'] = self.maven_jnlp_server.name
    app_config[RAILS_ENV]['default_maven_jnlp_family'] = self.maven_jnlp_family.name<commit_msg>comment out saving of settings-backup.yml<commit_after>require 'fileutils'

class Admin::Project < ActiveRecord::Base
  set_table_name "admin_projects"
  
  belongs_to :user

  belongs_to :maven_jnlp_server, :class_name => "MavenJnlp::MavenJnlpServer"
  belongs_to :maven_jnlp_family, :class_name => "MavenJnlp::MavenJnlpFamily"

  serialize :states_and_provinces
 
  acts_as_replicatable
  
  include Changeable
  
  self.extend SearchableModel
  
  @@searchable_attributes = %w{name description}

  def before_save
    if snapshot_enabled
      self.jnlp_version_str = maven_jnlp_family.snapshot_version
    end
  end
  
  def after_save
    if name == APP_CONFIG[:site_name] && url == APP_CONFIG[:site_url]
      write_to_settings_yml
    end
    if self.enable_default_users
      User.unsuspend_default_users
    else
      User.suspend_default_users
    end
  end

  def write_to_settings_yml
    new_settings = generate_settings_yml
    # FileUtils.copy("#{RAILS_ROOT}/config/settings.yml", "#{RAILS_ROOT}/config/settings-backup.yml")
    File.open("#{RAILS_ROOT}/config/settings.yml", 'w') do |f|
      f.write new_settings
    end
  end

  def generate_settings_yml
    app_config = YAML.load_file("#{RAILS_ROOT}/config/settings.yml")
    app_config[RAILS_ENV]['site_name'] = self.name
    app_config[RAILS_ENV]['site_url'] = self.url
    app_config[RAILS_ENV]['enable_default_users'] = self.enable_default_users
    app_config[RAILS_ENV]['description'] = self.description
    app_config[RAILS_ENV]['states_and_provinces'] = self.states_and_provinces
    app_config[RAILS_ENV]['default_maven_jnlp_server'] = self.maven_jnlp_server.name
    app_config[RAILS_ENV]['default_maven_jnlp_family'] = self.maven_jnlp_family.name
{'fraction_non_alphanumeric': 0.09772462077012835, 'fraction_numerical': 0.0, 'mean_word_length': 4.79222972972973, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, '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': '1752190', 'n_tokens_mistral': 1265, 'n_tokens_neox': 1223, 'n_words': 169}