<commit_before>class SiteConfig
  require 'json'
  require 'fileutils'

  CONFIG_DIR = File.expand_path('~/.config/static/')
  CONFIG_FILENAME = 'sites_config.json'
  CONFIG_FILE = File.join(CONFIG_DIR, CONFIG_FILENAME)

  def self.new_site(name, repo_url, dir, domain, local_url)
    check_config_exists
    sites = get_sites_json
    sites[name] = {:local => {:location => dir, :domain => local_url},
                   :remote => {:domain => domain, :gh_repo => repo_url}}

    save_config(sites)
  end

  def self.get_local_location(name)
    check_config_exists
    sites = get_sites_json
    return sites[name]['local']['location']
  end

  def self.get_repo_url(name)
    check_config_exists
    sites = get_sites_json
    return sites[name]['remote']['gh_repo']
  end

  def self.get_sites_list
    check_config_exists
    return get_sites_json.keys
  end

  def self.get_local_domain(name)
    check_config_exists
    sites = get_sites_json
    return sites[name]['local']['domain']
  end

  def self.remove(name)
    check_config_exists
    sites = get_sites_json
    sites.delete(name)
    save_config(sites)
  end

  private
  def self.save_config(sites)
    File.open(CONFIG_FILE, 'w') { |f| f.write(JSON.generate(sites))}
  end

  private
  def self.check_config_exists
    unless File.exist?(CONFIG_FILE)
      FileUtils.mkpath(CONFIG_DIR)
      File.open(CONFIG_FILE, 'w') { |f| f.write('{}') }
    end
  end

  private
  def self.get_sites_json
    return JSON.parse(File.open(CONFIG_FILE).read)
  end
end
<commit_msg>Pretty generate JSON to output file.<commit_after>class SiteConfig
  require 'json'
  require 'fileutils'

  CONFIG_DIR = File.expand_path('~/.config/static/')
  CONFIG_FILENAME = 'sites_config.json'
  CONFIG_FILE = File.join(CONFIG_DIR, CONFIG_FILENAME)

  def self.new_site(name, repo_url, dir, domain, local_url)
    check_config_exists
    sites = get_sites_json
    sites[name] = {:local => {:location => dir, :domain => local_url},
                   :remote => {:domain => domain, :gh_repo => repo_url}}

    save_config(sites)
  end

  def self.get_local_location(name)
    check_config_exists
    sites = get_sites_json
    return sites[name]['local']['location']
  end

  def self.get_repo_url(name)
    check_config_exists
    sites = get_sites_json
    return sites[name]['remote']['gh_repo']
  end

  def self.get_sites_list
    check_config_exists
    return get_sites_json.keys
  end

  def self.get_local_domain(name)
    check_config_exists
    sites = get_sites_json
    return sites[name]['local']['domain']
  end

  def self.remove(name)
    check_config_exists
    sites = get_sites_json
    sites.delete(name)
    save_config(sites)
  end

  private
  def self.save_config(sites)
    File.open(CONFIG_FILE, 'w') { |f| f.write(JSON.pretty_generate(sites))}
  end

  private
  def self.check_config_exists
    unless File.exist?(CONFIG_FILE)
      FileUtils.mkpath(CONFIG_DIR)
      File.open(CONFIG_FILE, 'w') { |f| f.write('{}') }
    end
  end

  private
  def self.get_sites_json
    return JSON.parse(File.open(CONFIG_FILE).read)
  end
end

{'fraction_non_alphanumeric': 0.11129032258064517, 'fraction_numerical': 0.0, 'mean_word_length': 3.6214605067064083, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, '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': '2712436', 'n_tokens_mistral': 1108, 'n_tokens_neox': 1047, 'n_words': 205}