coordinator 0.0.11 → 0.0.12
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/coordinator/base.rb +9 -0
- data/lib/coordinator/version.rb +1 -1
- data/test/unit/base_test.rb +33 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f57530d2f47e8f82ab96f074dfcc9f7f2a08409b
|
4
|
+
data.tar.gz: bf2be6add48183ecd18bc27a84f2a8f6ce2762ba
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8fc9c5ae89732c5b00a7908f9b1cd049bf73b2a900bb52f60d1fdbfe9a45a0a84045f07d24463aba820d40c206b2a0c437eeceaa3790367fcccb9047a6c9d26f
|
7
|
+
data.tar.gz: 17da52136062072f28cdb1cbe2af22bb947599ae8a8a00a1ec799672eef28bbde600fcbcec135bbf0c76e5e613e50e9b673a5109ccb41b4b1cc10bf4154a4790
|
data/lib/coordinator/base.rb
CHANGED
@@ -36,10 +36,19 @@ module Coordinator
|
|
36
36
|
queue_for_skill(skill).details
|
37
37
|
end
|
38
38
|
|
39
|
+
def position(skill, task)
|
40
|
+
index = queue_for_skill(skill).items.index(task)
|
41
|
+
index ? index + 1 : -1
|
42
|
+
end
|
43
|
+
|
39
44
|
def length_all
|
40
45
|
@queues.inject(0) { |sum, queue| sum + queue.length }
|
41
46
|
end
|
42
47
|
|
48
|
+
def length(skill)
|
49
|
+
queue_for_skill(skill).length
|
50
|
+
end
|
51
|
+
|
43
52
|
def peek_all
|
44
53
|
@queues.map(&:peek).compact
|
45
54
|
end
|
data/lib/coordinator/version.rb
CHANGED
data/test/unit/base_test.rb
CHANGED
@@ -80,6 +80,21 @@ describe 'Coordinator::Base' do
|
|
80
80
|
end
|
81
81
|
end
|
82
82
|
|
83
|
+
describe 'length' do
|
84
|
+
it 'returns the total amount of tasks for a particular queue' do
|
85
|
+
@coordinator.add_task("medium", 1)
|
86
|
+
@coordinator.add_task("medium", 2)
|
87
|
+
@coordinator.add_task("low", 3)
|
88
|
+
|
89
|
+
assert_equal 2, @coordinator.length("medium")
|
90
|
+
assert_equal 1, @coordinator.length("low")
|
91
|
+
end
|
92
|
+
|
93
|
+
it 'returns 0 for no tasks enqueued' do
|
94
|
+
assert_equal 0, @coordinator.length_all
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
83
98
|
describe 'peek_all' do
|
84
99
|
it 'returns the top item from each queue' do
|
85
100
|
@coordinator.add_task("medium", 1)
|
@@ -94,4 +109,22 @@ describe 'Coordinator::Base' do
|
|
94
109
|
assert_equal [], @coordinator.peek_all
|
95
110
|
end
|
96
111
|
end
|
112
|
+
|
113
|
+
describe 'position' do
|
114
|
+
it 'returns the position in the queue' do
|
115
|
+
@coordinator.add_task("medium", 1)
|
116
|
+
@coordinator.add_task("medium", 2)
|
117
|
+
@coordinator.add_task("low", 3)
|
118
|
+
@coordinator.add_task("high", 4)
|
119
|
+
|
120
|
+
assert_equal 1, @coordinator.position("medium", 1)
|
121
|
+
assert_equal 2, @coordinator.position("medium", 2)
|
122
|
+
assert_equal 1, @coordinator.position("low", 3)
|
123
|
+
assert_equal 1, @coordinator.position("high", 4)
|
124
|
+
end
|
125
|
+
|
126
|
+
it 'returns -1 if the task is not in the queue' do
|
127
|
+
assert_equal -1, @coordinator.position("medium", 999)
|
128
|
+
end
|
129
|
+
end
|
97
130
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: coordinator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.12
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tyler Mercier
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-09-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: http
|