Class: MockBeaneater::Tubes
- Inherits:
-
Object
- Object
- MockBeaneater::Tubes
- Defined in:
- lib/mock_beaneater/tube/collection.rb
Instance Attribute Summary collapse
-
#all ⇒ Object
readonly
Returns the value of attribute all.
-
#pool ⇒ Object
readonly
Returns the value of attribute pool.
-
#used ⇒ Object
readonly
Returns the value of attribute used.
-
#watched ⇒ Object
readonly
Returns the value of attribute watched.
Instance Method Summary collapse
- #find(tube_name) ⇒ Object (also: #[])
- #first_or_create(tube_name) ⇒ Object
-
#initialize(pool) ⇒ Tubes
constructor
A new instance of Tubes.
- #reserve(timeout = nil) ⇒ Object
- #use(tube_name) ⇒ Object
- #watch(*names) ⇒ Object
- #watch!(*names) ⇒ Object
Constructor Details
#initialize(pool) ⇒ Tubes
Returns a new instance of Tubes.
5 6 7 8 9 10 |
# 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 |
Instance Attribute Details
#all ⇒ Object (readonly)
Returns the value of attribute all.
3 4 5 |
# File 'lib/mock_beaneater/tube/collection.rb', line 3 def all @all end |
#pool ⇒ Object (readonly)
Returns the value of attribute pool.
3 4 5 |
# File 'lib/mock_beaneater/tube/collection.rb', line 3 def pool @pool end |
#used ⇒ Object (readonly)
Returns the value of attribute used.
3 4 5 |
# File 'lib/mock_beaneater/tube/collection.rb', line 3 def used @used end |
#watched ⇒ Object (readonly)
Returns the value of attribute watched.
3 4 5 |
# File 'lib/mock_beaneater/tube/collection.rb', line 3 def watched @watched end |
Instance Method Details
#find(tube_name) ⇒ Object Also known as: []
12 13 14 |
# File 'lib/mock_beaneater/tube/collection.rb', line 12 def find(tube_name) first_or_create(tube_name) end |
#first_or_create(tube_name) ⇒ Object
45 46 47 |
# 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) ⇒ Object
17 18 19 20 21 22 23 24 25 26 |
# 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) ⇒ Object
41 42 43 |
# File 'lib/mock_beaneater/tube/collection.rb', line 41 def use(tube_name) @used = first_or_create(tube_name) end |
#watch(*names) ⇒ Object
28 29 30 31 32 |
# 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) ⇒ Object
34 35 36 37 38 39 |
# File 'lib/mock_beaneater/tube/collection.rb', line 34 def watch!(*names) @watched = [] names.each do |n| @watched << first_or_create(n) end end |