<commit_before>module EventStore
  module Messaging
    class Writer
      attr_accessor :category_name

      dependency :writer, Client::HTTP::Vertx::Writer
      dependency :logger, Telemetry::Logger

      def initialize(category_name=nil)
        @category_name = category_name
      end

      def self.build(category_name=nil)
        logger.trace "Building (Category Name: #{category_name})"
        new(category_name).tap do |instance|
          Client::HTTP::Vertx::Writer.configure instance, category_name
          Telemetry::Logger.configure instance
          logger.debug "Built (Category Name: #{category_name})"
        end
      end

      def self.configure(receiver, attribute_name=nil)
        attribute_name ||= :writer
        logger.trace "Configuring (Receiver: #{receiver.inspect}, Category Name: #{category_name})"
        instance = build(category_name)

        receiver.send attribute_name, instance

        logger.debug "Configured (Receiver: #{receiver.inspect}, Category Name: #{category_name})"

        instance
      end

      # TODO Remove nillability for stream ID [Scott, Tue Jun 23 2015]
      def write(message, stream_id=nil)
        logger.trace "Writing (Message Type: #{message.message_type}, Category Name: #{category_name})"
        event_data = EventStore::Messaging::Message::Conversion::EventData.! message
        writer.! event_data
        logger.debug "Wrote (Message Type: #{message.message_type}, Category Name: #{category_name})"

        event_data
      end

      def self.logger
        @logger ||= Telemetry::Logger.get self
      end

      class Substitute
        def self.build
          new
        end

        def messages
          @messages ||= []
        end<commit_msg>Only a single writer can be configured (receiver's writer attribute name is no longer an argument to configuration)<commit_after>module EventStore
  module Messaging
    class Writer
      attr_accessor :category_name

      dependency :writer, Client::HTTP::Vertx::Writer
      dependency :logger, Telemetry::Logger

      def initialize(category_name=nil)
        @category_name = category_name
      end

      def self.build(category_name=nil)
        logger.trace "Building (Category Name: #{category_name})"
        new(category_name).tap do |instance|
          Client::HTTP::Vertx::Writer.configure instance, category_name
          Telemetry::Logger.configure instance
          logger.debug "Built (Category Name: #{category_name})"
        end
      end

      def self.configure(receiver)
        attribute_name ||= :writer
        logger.trace "Configuring (Receiver: #{receiver.inspect}, Category Name: #{category_name})"

        instance = build(category_name)

        receiver.writer = instance

        logger.debug "Configured (Receiver: #{receiver.inspect}, Category Name: #{category_name})"

        instance
      end

      # TODO Remove nillability for stream ID [Scott, Tue Jun 23 2015]
      def write(message, stream_id=nil)
        logger.trace "Writing (Message Type: #{message.message_type}, Category Name: #{category_name})"
        event_data = EventStore::Messaging::Message::Conversion::EventData.! message
        writer.! event_data
        logger.debug "Wrote (Message Type: #{message.message_type}, Category Name: #{category_name})"

        event_data
      end

      def self.logger
        @logger ||= Telemetry::Logger.get self
      end

      class Substitute
        def self.build
          new
        end

        def messages
          @messages ||= []
        end
{'fraction_non_alphanumeric': 0.09525147513346445, 'fraction_numerical': 0.0033717336330429896, 'mean_word_length': 2.7473684210526317, 'pattern_counts': {'":': 0, '<': 3, '<?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': '1990958', 'n_tokens_mistral': 971, 'n_tokens_neox': 919, 'n_words': 254}