<commit_before># frozen_string_literal: true

require 'logger'

begin
  require 'pry-byebug'
rescue LoadError
  nil
end

LOGGER = Logger.new($stdout, level: :debug)

class WatchRun
  TMP_DIR = File.join(__dir__, 'tmp')

  attr_reader :filename

  def initialize(filename:, action:, directory:)
    @filename =
      if filename.match? %r{^(/|~|[A-Z]:)} then filename
      else File.join(TMP_DIR, filename)
      end
    @directory = directory
    @action = action
    debug "action = #{action}"
  end

  def start
    debug 'start'
    File.write(@filename, 'content1') unless @action == :create
  end

  def run
    start

    make_changes

    wait seconds: 2

    stop
  end

  def stop
    debug 'stop'
    FileUtils.rm_r(@filename) if File.exist?(@filename)
  end

  private

  def make_changes
    debug "make changes, @action = #{@action}, @filename = #{@filename}"
    if @action == :delete
      FileUtils.remove(@filename)
    elsif @directory
      FileUtils.mkdir_p(@filename)
    else
      File.write(@filename, 'content2')
    end
  end

  ENVIRONMENT_COEFFICIENTS = {
    -> { ENV['CI'] } => 4,
    -> { RUBY_PLATFORM == 'java' } => 3,
    -> { Gem::Platform.local.os == 'darwin' } => 3
  }.freeze

  def wait(seconds:, interval:, &block)
    seconds ||= 1<commit_msg>(Try to) Speed up tests<commit_after># frozen_string_literal: true

require 'logger'

begin
  require 'pry-byebug'
rescue LoadError
  nil
end

LOGGER = Logger.new($stdout, level: :debug)

class WatchRun
  TMP_DIR = File.join(__dir__, 'tmp')

  attr_reader :filename

  def initialize(filename:, action:, directory:)
    @filename =
      if filename.match? %r{^(/|~|[A-Z]:)} then filename
      else File.join(TMP_DIR, filename)
      end
    @directory = directory
    @action = action
    debug "action = #{action}"
  end

  def start
    debug 'start'
    File.write(@filename, 'content1') unless @action == :create
  end

  def run
    start

    make_changes

    wait seconds: 1

    stop
  end

  def stop
    debug 'stop'
    FileUtils.rm_r(@filename) if File.exist?(@filename)
  end

  private

  def make_changes
    debug "make changes, @action = #{@action}, @filename = #{@filename}"
    if @action == :delete
      FileUtils.remove(@filename)
    elsif @directory
      FileUtils.mkdir_p(@filename)
    else
      File.write(@filename, 'content2')
    end
  end

  ENVIRONMENT_COEFFICIENTS = {
    -> { ENV['CI'] } => 4,
    -> { RUBY_PLATFORM == 'java' } => 3,
    -> { Gem::Platform.local.os == 'darwin' } => 4
  }.freeze

  def wait(seconds:, interval:, &block)
    seconds ||= 1
{'fraction_non_alphanumeric': 0.1372093023255814, 'fraction_numerical': 0.005426356589147287, 'mean_word_length': 2.9165402124430955, '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': '2315212', 'n_tokens_mistral': 912, 'n_tokens_neox': 875, 'n_words': 223}