class MockBeaneater::Tubes
Attributes
all[R]
pool[R]
used[R]
watched[R]
Public Class Methods
new(pool)
click to toggle source
# File lib/mock_beaneater/tube/collection.rb, line 5 def initialize(pool) @pool = pool @all = [Tube.new(@pool, 'default')] @watched = [find('default')] @used = find('default') end
Public Instance Methods
find(tube_name)
click to toggle source
# File lib/mock_beaneater/tube/collection.rb, line 12 def find(tube_name) first_or_create(tube_name) end
Also aliased as: []
first_or_create(tube_name)
click to toggle source
# File lib/mock_beaneater/tube/collection.rb, line 45 def first_or_create(tube_name) @all.find { |t| t.name == tube_name } || (@all << Tube.new(@pool, tube_name)).last end
reserve(timeout=nil)
click to toggle source
# File lib/mock_beaneater/tube/collection.rb, line 17 def reserve(timeout=nil) job = nil @all.each do |t| if t.peek('ready') job = t.reserve(timeout) break end end job end
use(tube_name)
click to toggle source
# File lib/mock_beaneater/tube/collection.rb, line 41 def use(tube_name) @used = first_or_create(tube_name) end
watch(*names)
click to toggle source
# File lib/mock_beaneater/tube/collection.rb, line 28 def watch(*names) names.each do |n| @watched << first_or_create(n) end end
watch!(*names)
click to toggle source
# File lib/mock_beaneater/tube/collection.rb, line 34 def watch!(*names) @watched = [] names.each do |n| @watched << first_or_create(n) end end