<commit_before>require 'rb-inotify'
require 'io/nonblock'

module EMDirWatcher
module Platform
module Linux

module Native
  extend FFI::Library
  ffi_lib "c"
  attach_function :close, [:int], :int
end

class Watcher

  def initialize path, inclusions, exclusions
    @notifier = INotify::Notifier.new

    @notifier.watch(path, :recursive, :attrib, :modify, :create,
                    :delete, :delete_self, :moved_from, :moved_to,
                    :move_self) do |event|
      yield event.absolute_name
    end

    @conn = EM.watch @notifier.to_io do |conn|
      class << conn
        attr_accessor :notifier

        def notify_readable
          @notifier.process
        end
      end
      conn.notifier = @notifier
      conn.notify_readable = true
    end
  end

  def when_ready_to_use
      yield
  end

  def ready_to_use?; true; end

  def stop
    Native.close @notifier.fd
  end
end

end
end
end<commit_msg>Use @notifier.close from rb-inotify 0.8.0<commit_after>require 'rb-inotify'
require 'io/nonblock'

module EMDirWatcher
module Platform
module Linux

class Watcher

  def initialize path, inclusions, exclusions
    @notifier = INotify::Notifier.new

    @notifier.watch(path, :recursive, :attrib, :modify, :create,
                    :delete, :delete_self, :moved_from, :moved_to,
                    :move_self) do |event|
      yield event.absolute_name
    end

    @conn = EM.watch @notifier.to_io do |conn|
      class << conn
        attr_accessor :notifier

        def notify_readable
          @notifier.process
        end
      end
      conn.notifier = @notifier
      conn.notify_readable = true
    end
  end

  def when_ready_to_use
      yield
  end

  def ready_to_use?; true; end

  def stop
    @notifier.close
  rescue SystemCallError
  end
end

end
end
end
{'fraction_non_alphanumeric': 0.07922437673130193, 'fraction_numerical': 0.0016620498614958448, 'mean_word_length': 2.479768786127168, 'pattern_counts': {'":': 0, '<': 7, '<?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': '2960246', 'n_tokens_mistral': 615, 'n_tokens_neox': 592, 'n_words': 157}