<commit_before>require 'find'
require 'digest/sha1'

require 'listen/adapter'
require 'listen/adapters/darwin'
require 'listen/adapters/linux'
require 'listen/adapters/polling'
require 'listen/adapters/windows'

module Listen
  class Listener
    attr_accessor :directory, :ignored_paths, :file_filters, :sha1_checksums, :paths, :adapter, :paused

    # Default paths that gets ignored by the listener
    DEFAULT_IGNORED_PATHS = %w[.bundle .git .DS_Store log tmp vendor]

    # Initialize the file listener.
    #
    # @param [String, Pathname] directory the directory to watch
    # @param [Hash] options the listen options
    # @option options [String] ignore a list of paths to ignore
    # @option options [Regexp] filter a list of regexps file filters
    # @option options [Float] latency the delay between checking for changes in seconds
    # @option options [Boolean] force_polling whether to force the polling adapter or not
    # @option options [String, Boolean] polling_fallback_message to change polling fallback message or remove it
    #
    # @yield [modified, added, removed] the changed files
    # @yieldparam [Array<String>] modified the list of modified files
    # @yieldparam [Array<String>] added the list of added files
    # @yieldparam [Array<String>] removed the list of removed files
    #
    # @return [Listen::Listener] the file listener
    #
    def initialize(directory, options = {}, &block)
      @directory      = directory
      @ignored_paths  = DEFAULT_IGNORED_PATHS
      @file_filters   = []
      @sha1_checksums = {}
      @block          = block
      @ignored_paths += Array(options.delete(:ignore)) if options[:ignore]
      @file_filters  += Array(options.delete(:filter)) if options[:filter]

      @adapter_options = options
    end

    # Initialize the adapter and the @paths concurrently and start the adapter.
    #
    def start
      t = Thread.new { @adapter = initialize_adapter }
      init_paths
      t.join
      @adapter.start
    end

    # Stop the adapter.
    #
    def stop
      @adapter.stop
    end

    # Pause the adapter
    #
    def pause
      @adapter.paused = true
    end

    # Re-initialize @paths and unpause the adapter
    #
    def unpause
      init_paths
      @adapter.paused = false
    end

    # Is adapter paused
    #
    # @return [Boolean] adapter paused status
    #
    def paused?
      !!@adapter && @adapter.paused == true
    end

    # Block until the adapter started or has been unpaused
    #
    def wait_until_listening
      if @adapter.stop.nil? # Adapter didn't start yet
        @adapter.wait_until_started
      elsif @adapter.paused
        sleep 0.1 until !@adapter.paused
      end
    end

    # Add ignored path to the listener.
    #
    # @example Ignore some paths<commit_msg>Remove wait_until_listening method<commit_after>require 'find'
require 'digest/sha1'

require 'listen/adapter'
require 'listen/adapters/darwin'
require 'listen/adapters/linux'
require 'listen/adapters/polling'
require 'listen/adapters/windows'

module Listen
  class Listener
    attr_accessor :directory, :ignored_paths, :file_filters, :sha1_checksums, :paths, :adapter, :paused

    # Default paths that gets ignored by the listener
    DEFAULT_IGNORED_PATHS = %w[.bundle .git .DS_Store log tmp vendor]

    # Initialize the file listener.
    #
    # @param [String, Pathname] directory the directory to watch
    # @param [Hash] options the listen options
    # @option options [String] ignore a list of paths to ignore
    # @option options [Regexp] filter a list of regexps file filters
    # @option options [Float] latency the delay between checking for changes in seconds
    # @option options [Boolean] force_polling whether to force the polling adapter or not
    # @option options [String, Boolean] polling_fallback_message to change polling fallback message or remove it
    #
    # @yield [modified, added, removed] the changed files
    # @yieldparam [Array<String>] modified the list of modified files
    # @yieldparam [Array<String>] added the list of added files
    # @yieldparam [Array<String>] removed the list of removed files
    #
    # @return [Listen::Listener] the file listener
    #
    def initialize(directory, options = {}, &block)
      @directory      = directory
      @ignored_paths  = DEFAULT_IGNORED_PATHS
      @file_filters   = []
      @sha1_checksums = {}
      @block          = block
      @ignored_paths += Array(options.delete(:ignore)) if options[:ignore]
      @file_filters  += Array(options.delete(:filter)) if options[:filter]

      @adapter_options = options
    end

    # Initialize the adapter and the @paths concurrently and start the adapter.
    #
    def start
      t = Thread.new { @adapter = initialize_adapter }
      init_paths
      t.join
      @adapter.start
    end

    # Stop the adapter.
    #
    def stop
      @adapter.stop
    end

    # Pause the adapter
    #
    def pause
      @adapter.paused = true
    end

    # Re-initialize @paths and unpause the adapter
    #
    def unpause
      init_paths
      @adapter.paused = false
    end

    # Is adapter paused
    #
    # @return [Boolean] adapter paused status
    #
    def paused?
      !!@adapter && @adapter.paused == true
    end

    # Add ignored path to the listener.
    #
    # @example Ignore some paths
{'fraction_non_alphanumeric': 0.08299065420560747, 'fraction_numerical': 0.0014953271028037382, 'mean_word_length': 2.863537906137184, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '883519', 'n_tokens_mistral': 1570, 'n_tokens_neox': 1496, 'n_words': 521}