Class: MockBeaneater::Tubes

Inherits:
Object
  • Object
show all
Defined in:
lib/mock_beaneater/tube/collection.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#allObject (readonly)

Returns the value of attribute all.



3
4
5
# File 'lib/mock_beaneater/tube/collection.rb', line 3

def all
  @all
end

#poolObject (readonly)

Returns the value of attribute pool.



3
4
5
# File 'lib/mock_beaneater/tube/collection.rb', line 3

def pool
  @pool
end

#usedObject (readonly)

Returns the value of attribute used.



3
4
5
# File 'lib/mock_beaneater/tube/collection.rb', line 3

def used
  @used
end

#watchedObject (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