Class: FileTopic

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

Overview

FileTopic - a topic to post messages to that queues can listen to

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(channel_location, topic_name) ⇒ FileTopic

Returns a new instance of FileTopic.



7
8
9
10
# File 'lib/file_topic.rb', line 7

def initialize(channel_location, topic_name)
  @topic_location = channel_location + '/' + topic_name
  FileUtils.mkdir_p @topic_location
end

Instance Attribute Details

#topic_locationObject (readonly)

Returns the value of attribute topic_location.



6
7
8
# File 'lib/file_topic.rb', line 6

def topic_location
  @topic_location
end

Instance Method Details

#publish(message) ⇒ Object



12
13
14
15
16
17
18
# File 'lib/file_topic.rb', line 12

def publish(message)
  message_file = FileMessage.new SecureRandom.hex(20).to_s + '.msg'
  Dir.glob(@topic_location + '/*').select do |queue_location|
    next unless File.directory? queue_location
    message_file.write_message(queue_location, message)
  end
end