Class: SimplePublisher::Publisher

Inherits:
Object
  • Object
show all
Defined in:
lib/simple_publisher/publisher.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Publisher

Returns a new instance of Publisher.



5
6
7
8
9
10
11
12
13
# File 'lib/simple_publisher/publisher.rb', line 5

def initialize(attributes = {})
  unless attributes.keys.include?(:topic) and attributes.keys.include?(:connection)
    raise ArgumentError, "You must specify a connection and a topic"
  end
  
  attributes.each do |attr, value|
    send("#{attr}=", value)
  end
end

Instance Attribute Details

#connectionObject

Returns the value of attribute connection.



3
4
5
# File 'lib/simple_publisher/publisher.rb', line 3

def connection
  @connection
end

#topicObject

Returns the value of attribute topic.



3
4
5
# File 'lib/simple_publisher/publisher.rb', line 3

def topic
  @topic
end

Instance Method Details

#publish(raw_message) ⇒ Object



15
16
17
18
# File 'lib/simple_publisher/publisher.rb', line 15

def publish(raw_message)
  message = Message.new(raw_message)
  connection.write(:message => message, :to => topic)
end