Sha256: e1b790ed3b59708143cc4b3cae59fbb2e962845ac8da6d4aa78b64a9761ec099

Contents?: true

Size: 627 Bytes

Versions: 4

Compression:

Stored size: 627 Bytes

Contents

module Alondra
  class Message
    attr_reader :content
    attr_reader :channel_names

    def initialize(content, channel_names)
      @content       = content
      @channel_names = channel_names
    end

    def enqueue
      MessageQueueClient.push self
    end

    def send_to_channels
      channels.each do |channel|
        channel.receive self
      end
    end

    def as_json
      {:message => content, :channel_names => channel_names}
    end

    def to_json
      ActiveSupport::JSON.encode(as_json)
    end

    private

    def channels
      channel_names.collect { |name| Channel[name] }
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
alondra-0.1.1 lib/alondra/message.rb
alondra-0.1.0 lib/alondra/message.rb
alondra-0.0.4 lib/alondra/message.rb
alondra-0.0.3 lib/alondra/message.rb