Class: Rider::Queue
- Inherits:
-
Object
- Object
- Rider::Queue
- Defined in:
- lib/rider/queue.rb
Instance Attribute Summary collapse
-
#filename ⇒ Object
readonly
Returns the value of attribute filename.
Instance Method Summary collapse
- #clear ⇒ Object
- #empty? ⇒ Boolean
-
#initialize(filename) ⇒ Queue
constructor
A new instance of Queue.
- #push(item) ⇒ Object
- #shift ⇒ Object
Constructor Details
#initialize(filename) ⇒ Queue
Returns a new instance of Queue.
4 5 6 7 |
# File 'lib/rider/queue.rb', line 4 def initialize(filename) raise(ArgumentError, "queues must have a filename") if !filename or filename.empty? @filename = filename end |
Instance Attribute Details
#filename ⇒ Object (readonly)
Returns the value of attribute filename.
3 4 5 |
# File 'lib/rider/queue.rb', line 3 def filename @filename end |
Instance Method Details
#clear ⇒ Object
31 32 33 34 |
# File 'lib/rider/queue.rb', line 31 def clear File.unlink(filename) if File.exist?(filename) return true end |
#empty? ⇒ Boolean
36 37 38 |
# File 'lib/rider/queue.rb', line 36 def empty? !File.exist?(filename) or File.open(filename).read == "" end |
#push(item) ⇒ Object
9 10 11 12 13 14 15 |
# File 'lib/rider/queue.rb', line 9 def push(item) Rider.log.debug("Q #{filename} PUSH #{item}") File.open(filename, "a") do |file| file.puts(item) end return true end |
#shift ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/rider/queue.rb', line 17 def shift if empty? Rider.log.debug("Q #{filename} SHIFT nil") return nil end lines = File.readlines(filename) item = lines.shift.strip File.open(filename, "w") do |file| file.write(lines.join) end Rider.log.debug("Q #{filename} SHIFT #{item}") return item end |