Class: FileQueue
- Inherits:
-
Object
- Object
- FileQueue
- Defined in:
- lib/file_queue.rb
Overview
FileQueue - simple queue to bind to a topic and pop messages
Instance Attribute Summary collapse
-
#queue_name ⇒ Object
readonly
Returns the value of attribute queue_name.
Instance Method Summary collapse
- #bind(file_topic) ⇒ Object
-
#initialize ⇒ FileQueue
constructor
A new instance of FileQueue.
- #latest_message_file ⇒ Object
- #pop ⇒ Object
Constructor Details
#initialize ⇒ FileQueue
Returns a new instance of FileQueue.
9 10 11 |
# File 'lib/file_queue.rb', line 9 def initialize @queue_name = SecureRandom.hex(20).to_s end |
Instance Attribute Details
#queue_name ⇒ Object (readonly)
Returns the value of attribute queue_name.
8 9 10 |
# File 'lib/file_queue.rb', line 8 def queue_name @queue_name end |
Instance Method Details
#bind(file_topic) ⇒ Object
13 14 15 16 |
# File 'lib/file_queue.rb', line 13 def bind(file_topic) @queue_location = file_topic.topic_location + '/' + @queue_name FileUtils.mkdir_p @queue_location end |
#latest_message_file ⇒ Object
25 26 27 28 29 30 |
# File 'lib/file_queue.rb', line 25 def files_sorted_by_time = Dir[@queue_location + '/*'].sort_by do |file| File.mtime(file) end files_sorted_by_time[0] end |
#pop ⇒ Object
18 19 20 21 22 23 |
# File 'lib/file_queue.rb', line 18 def pop = = File.read().chomp File.delete() end |