<commit_before># some extensions to the ZookeeperCallbacks classes, mainly convenience
# interrogators
module ZK
  module Callbacks
    module CallbackClassExt
      # allows for easier construction of a user callback block that will be
      # called with the callback object itself as an argument
      #
      # example:
      #   
      #   WatcherCallback.new do |cb|
      #     puts "watcher callback called with argument: #{cb.inspect}"
      #   end
      #
      #   "watcher callback called with argument: #<ZookeeperCallbacks::WatcherCallback:0x1018a3958 @state=3, @type=1, ...>"
      #
      #
      def create(&block)
        # honestly, i have no idea how this could *possibly* work, but it does...
        cb_inst = new { block.call(cb_inst) }
      end
    end

    module WatcherCallbackExt
      include ZookeeperConstants

      def connecting?
        @state == ZOO_CONNECTING_STATE
      end

      def associating?
        @state == ZOO_ASSOCIATING_STATE
      end

      def connected?
        @state == ZOO_CONNECTED_STATE
      end

      def created?
        @type == ZOO_CREATED_EVENT
      end

      def deleted?
        @type == ZOO_DELETED_EVENT
      end

      def changed?
        @type == ZOO_CHANGED_EVENT
      end

      def child?
        @type == ZOO_CHILD_EVENT
      end

      def session?
        @type == ZOO_SESSION_EVENT
      end

      def not_watching?
        @type == ZOO_NOTWATCHING_EVENT
      end
    end

  end   # Callbacks
end     # ZK

ZookeeperCallbacks::Callback.extend(::ZK::Callbacks::CallbackClassExt)

ZookeeperCallbacks::WatcherCallback.send(:include, ::ZK::Callbacks::WatcherCallbackExt)


<commit_msg>DRY up callback mixin<commit_after># some extensions to the ZookeeperCallbacks classes, mainly convenience
# interrogators
module ZK
  module Callbacks
    module CallbackClassExt
      # allows for easier construction of a user callback block that will be
      # called with the callback object itself as an argument
      #
      # example:
      #   
      #   WatcherCallback.new do |cb|
      #     puts "watcher callback called with argument: #{cb.inspect}"
      #   end
      #
      #   "watcher callback called with argument: #<ZookeeperCallbacks::WatcherCallback:0x1018a3958 @state=3, @type=1, ...>"
      #
      #
      def create(&block)
        # honestly, i have no idea how this could *possibly* work, but it does...
        cb_inst = new { block.call(cb_inst) }
      end
    end

    module WatcherCallbackExt
      include ZookeeperConstants

      STATES = %w[connecting associating connected auth_failed expired_session].freeze unless defined?(STATES)

      EVENT_TYPES = %w[created deleted changed child session notwatching].freeze unless defined?(EVENT_TYPES)

      STATES.each do |state|
        class_eval <<-RUBY, __FILE__, __LINE__ + 1
          def #{state}?
            @state == ZOO_#{state.upcase}_STATE
          end
        RUBY
      end

      EVENT_TYPES.each do |ev|
        class_eval <<-RUBY, __FILE__, __LINE__ + 1
          def #{ev}?
            @type == ZOO_#{ev.upcase}_EVENT
          end
        RUBY
      end

      alias :not_watching? :notwatching?
    end

  end   # Callbacks
end     # ZK

ZookeeperCallbacks::Callback.extend(::ZK::Callbacks::CallbackClassExt)

ZookeeperCallbacks::WatcherCallback.send(:include, ::ZK::Callbacks::WatcherCallbackExt)



{'fraction_non_alphanumeric': 0.08168097070139095, 'fraction_numerical': 0.007102693104468778, 'mean_word_length': 2.393574297188755, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 5, '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': '1264232', 'n_tokens_mistral': 1044, 'n_tokens_neox': 1009, 'n_words': 276}