<commit_before>class Hare::Message
  class << self
    def channel
      Hare::Server.channel
    end

    def exchange(exchange=nil, type: :fanout)
      if exchange.present?
        @type = type
        @exchange = channel.exchange(exchange, type: type)
      else
        @exchange || channel.default_exchange
      end
    end

    def routing_key(routing_key=nil)
      if routing_key.present?
        @routing_key = routing_key
      else
        @routing_key
      end
    end
  end

  attr_accessor :data

  def initialize(data=nil)
    @data = data || {}
  end

  def channel
    self.class.channel
  end

  def exchange
    self.class.exchange
  end

  def routing_key
    self.class.routing_key
  end

  def json
    data.present? ? data.to_json : {}.to_json
  end

  def send
    if exchange.name == ""
      if routing_key.present?
        exchange.publish(json, routing_key: routing_key)
      else
        raise "Routing key must be set (so we know what queue to send your message to.)"
      end
    else
      exchange.publish(json, routing_key: routing_key)
    end
  end
end<commit_msg>Namespace Message like every other class.<commit_after>module Hare
  class Message
    class << self
      def channel
        Hare::Server.channel
      end

      def exchange(exchange=nil, type: :direct)
        if exchange.present?
          @type = type
          @exchange = channel.exchange(exchange, type: type)
        else
          @exchange || channel.default_exchange
        end
      end

      def routing_key(routing_key=nil)
        if routing_key.present?
          @routing_key = routing_key
        else
          @routing_key
        end
      end
    end

    attr_accessor :data

    def initialize(data=nil)
      @data = data || {}
    end

    def channel
      self.class.channel
    end

    def exchange
      self.class.exchange
    end

    def routing_key
      self.class.routing_key
    end

    def json
      data.present? ? data.to_json : {}.to_json
    end

    def send
      if exchange.name == ""
        if routing_key.present?
          exchange.publish(json, routing_key: routing_key)
        else
          raise "Routing key must be set (so we know what queue to send your message to.)"
        end
      else
        exchange.publish(json, routing_key: routing_key)
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.07203751065643649, 'fraction_numerical': 0.0, 'mean_word_length': 1.9633838383838385, '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': '6468752', 'n_tokens_mistral': 732, 'n_tokens_neox': 691, 'n_words': 197}