<commit_before>module CelluloidPubsub
  class Client
    class PubSubWorker
      include Celluloid
      include Celluloid::Logger
      attr_accessor :actor, :connect_blk, :client, :options, :hostname, :port, :path

      def initialize(options, &connect_blk)
        options = options.stringify_keys!
        parse_options(options)
        raise "#{self}: Please provide an actor in the options list!!!" if @actor.blank?
        @connect_blk = connect_blk
        @client = Celluloid::WebSocket::Client.new("ws://#{@hostname}:#{@port}#{@path}", Actor.current)
      end
      
      def parse_options(options)
        raise 'Options is not a hash or is not present ' unless options.is_a?(Hash)
        @options = options.stringify_keys
        @actor = options.fetch(:actor, nil)
        @hostname = @options.fetch(:hostname, CelluloidPubsub::WebServer::HOST)
        @port = @options.fetch(:port, CelluloidPubsub::WebServer::PORT)
        @path = @options.fetch(:path, CelluloidPubsub::WebServer::PATH
      end

      def debug_enabled?
        CelluloidPubsub::WebServer.debug_enabled?
      end

      def subscribe(channel)
        subscription_data = { 'client_action' => 'subscribe', 'channel' => channel }
        debug("#{self.class} tries to subscribe  #{subscription_data}") if debug_enabled?
        async.chat(subscription_data)
      end

      def publish(channel, data)
        publishing_data = { 'client_action' => 'publish', 'channel' => channel, 'data' => data }
        debug(" #{self.class}  publishl to #{channel} message:  #{publishing_data}") if debug_enabled?
        async.chat(publishing_data)
      end

      def on_open
        debug("#{self.class} websocket connection opened") if debug_enabled?
        @connect_blk.call Actor.current
      end<commit_msg>Update client_pubsub.rb<commit_after>module CelluloidPubsub
  class Client
    class PubSubWorker
      include Celluloid
      include Celluloid::Logger
      attr_accessor :actor, :connect_blk, :client, :options, :hostname, :port, :path

      def initialize(options, &connect_blk)
        options = options.stringify_keys!
        parse_options(options)
        raise "#{self}: Please provide an actor in the options list!!!" if @actor.blank?
        @connect_blk = connect_blk
        @client = Celluloid::WebSocket::Client.new("ws://#{@hostname}:#{@port}#{@path}", Actor.current)
      end
      
      def parse_options(options)
        raise 'Options is not a hash ' unless options.is_a?(Hash)
        @options = options.stringify_keys
        @actor = options.fetch(:actor, nil)
        @hostname = @options.fetch(:hostname, CelluloidPubsub::WebServer::HOST)
        @port = @options.fetch(:port, CelluloidPubsub::WebServer::PORT)
        @path = @options.fetch(:path, CelluloidPubsub::WebServer::PATH
      end

      def debug_enabled?
        CelluloidPubsub::WebServer.debug_enabled?
      end

      def subscribe(channel)
        subscription_data = { 'client_action' => 'subscribe', 'channel' => channel }
        debug("#{self.class} tries to subscribe  #{subscription_data}") if debug_enabled?
        async.chat(subscription_data)
      end

      def publish(channel, data)
        publishing_data = { 'client_action' => 'publish', 'channel' => channel, 'data' => data }
        debug(" #{self.class}  publishl to #{channel} message:  #{publishing_data}") if debug_enabled?
        async.chat(publishing_data)
      end

      def on_open
        debug("#{self.class} websocket connection opened") if debug_enabled?
        @connect_blk.call Actor.current
      end
{'fraction_non_alphanumeric': 0.11884787472035795, 'fraction_numerical': 0.0, 'mean_word_length': 3.1352601156069366, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, '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': '1869127', 'n_tokens_mistral': 1029, 'n_tokens_neox': 1042, 'n_words': 242}