<commit_before>require 'fileutils'
require 'pathname'
require 'erb'

class TemplateCopier

  def initialize(options)
    @cygwin_home = options[:cygwin_home]
    @user_home = options[:user_home]
    @templates_dir = options[:templates_dir]
  end

  def copy_all
    profile_skeleton = File.join(@cygwin_home, 'etc/skel')
    all_files_in(profile_skeleton).each { |file| FileUtils.cp(file, @user_home) }

    all_files_in(@templates_dir).each { |file| process_template(file) }
  end

  private

  def all_files_in(dir)
    Dir.glob(File.join(dir, '**/*'), File::FNM_DOTMATCH).reject { |file_or_dir| Dir.exist?(file_or_dir) }
  end

  def process_template(template_file)<commit_msg>Make sure that user home exists before copying files there<commit_after>require 'fileutils'
require 'pathname'
require 'erb'

class TemplateCopier

  def initialize(options)
    @cygwin_home = options[:cygwin_home]
    @user_home = options[:user_home]
    @templates_dir = options[:templates_dir]
  end

  def copy_all
    profile_skeleton = File.join(@cygwin_home, 'etc/skel')
    all_files_in(profile_skeleton).each { |file| copy_to_user_home(file) }

    all_files_in(@templates_dir).each { |file| process_template(file) }
  end

  private

  def all_files_in(dir)
    Dir.glob(File.join(dir, '**/*'), File::FNM_DOTMATCH).reject { |file_or_dir| Dir.exist?(file_or_dir) }
  end

  def copy_to_user_home(file)
    # If the directory doesn't exist, 'cp' would create a file with the same name,
    # so let's make sure the directory exists first.
    # TODO: the directory will be owned by Administrators - change it? (though this happens only when testing)
    FileUtils.mkdir_p(@user_home)

    FileUtils.cp(file, @user_home)
  end

  def process_template(template_file)
{'fraction_non_alphanumeric': 0.1113013698630137, 'fraction_numerical': 0.0, 'mean_word_length': 4.691558441558442, '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': '7183634', 'n_tokens_mistral': 617, 'n_tokens_neox': 599, 'n_words': 131}