<commit_before>class Mangos::Mangos
  def initialize(root_path)
    raise "root_path must be an instance of Pathname" unless root_path.is_a?(Pathname)

    @root_path = root_path
    @mangos_path = root_path + ".mangos/"
  end

  def update
    update_app
    Mangos::Update.new(self)
  end

  def install
    mangos_path.mkdir unless File.exists?(mangos_path)

    update_app
  end

  def update_app
    FileUtils.cp_r(Mangos::Mangos.gem_path + "app/.", mangos_path)
    FileUtils.chmod_R(0755, mangos_path)
  end

  def self.load_json(path)
    if File.exists?(path)
      JSON.parse(File.read(path))
    else
      nil
    end
  end

  def self.save_json(path, data)
    File.open(path, "w") { |f| f << data.to_json }
  end
end<commit_msg>Add development mode, and symlink the app files into the gem in development mode only<commit_after>class Mangos::Mangos
  def initialize(root_path)
    raise "root_path must be an instance of Pathname" unless root_path.is_a?(Pathname)

    @root_path = root_path
    @mangos_path = root_path + ".mangos/"
  end

  def update
    update_app
    Mangos::Update.new(self)
  end

  def install
    mangos_path.mkdir unless File.exists?(mangos_path)

    update_app
  end

  def update_app
    dev = ENV["MANGOS_ENV"] == "development"

    app_children_paths.each do |file|
      mangos_file = mangos_path + file.basename
      FileUtils.rm_rf(mangos_file, :verbose => dev)
    end

    if dev
      app_children_paths.each do |file|
        mangos_file = mangos_path + file.basename
        FileUtils.ln_sf(file, mangos_file, :verbose => dev)
      end
    else
      FileUtils.cp_r(Mangos::Mangos.gem_path + "app/.", mangos_path, :verbose => dev)
    end

    FileUtils.chmod_R(0755, mangos_path, :verbose => dev)
  end

  def self.load_json(path)
    if File.exists?(path)
      JSON.parse(File.read(path))
    else
      nil
    end
  end

  def self.save_json(path, data)
    File.open(path, "w") { |f| f << data.to_json }
  end

  private
  def app_children_paths
    app_path = Mangos::Mangos.gem_path + "app/"
    app_path.children.reject { |f| f.basename.to_s == "img"} #TODO: Deal with this directory properly
  end
end
{'fraction_non_alphanumeric': 0.10295475530932595, 'fraction_numerical': 0.003693444136657433, 'mean_word_length': 3.0886792452830187, 'pattern_counts': {'":': 0, '<': 7, '<?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': '215304', 'n_tokens_mistral': 824, 'n_tokens_neox': 795, 'n_words': 180}