seam 1.0.1 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/seam/version.rb +1 -1
- data/lib/seam/worker.rb +21 -0
- data/spec/seam/worker_spec.rb +49 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f77d3c7f56742635b5fda7bbd4fd6273e4f98293
|
4
|
+
data.tar.gz: 39a5730134d7d8cc53b028a36c915873809b6d54
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 113c2d036b72d7e07e99e19aca09ea4a21d9da7fb608fc6c1470b8ee51d5bab28b5c0433edb3fad0b25699488e63271715d0b3373decd347c3a84d7f89033e68
|
7
|
+
data.tar.gz: 6e1b2fa575ea9c47294321e1e2f606ab15eb490555dfeccd80409cfee0402a4e0942a1b479c7e004446a1f00df9cf80c04509e2c6b03a6b7a825b13fd58badae
|
data/lib/seam/version.rb
CHANGED
data/lib/seam/worker.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
module Seam
|
2
|
+
|
2
3
|
class Worker
|
4
|
+
|
3
5
|
def handles step
|
4
6
|
@step = step
|
5
7
|
end
|
@@ -11,6 +13,23 @@ module Seam
|
|
11
13
|
after_process
|
12
14
|
end
|
13
15
|
|
16
|
+
def self.inherited handler
|
17
|
+
@handlers ||= []
|
18
|
+
@handlers << handler
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.handler_for step
|
22
|
+
@handlers.each do |handler|
|
23
|
+
instance = handler.new
|
24
|
+
return instance if instance.handles == step
|
25
|
+
end
|
26
|
+
nil
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.all
|
30
|
+
(@handlers || []).map { |x| x.new }
|
31
|
+
end
|
32
|
+
|
14
33
|
def execute_all
|
15
34
|
efforts_to_execute.each { |e| execute e }
|
16
35
|
end
|
@@ -141,5 +160,7 @@ module Seam
|
|
141
160
|
def save_the_effort
|
142
161
|
effort.save
|
143
162
|
end
|
163
|
+
|
144
164
|
end
|
165
|
+
|
145
166
|
end
|
data/spec/seam/worker_spec.rb
CHANGED
@@ -19,6 +19,55 @@ describe "worker" do
|
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
|
+
describe "inherited & all" do
|
23
|
+
|
24
|
+
before do
|
25
|
+
Seam::Worker.instance_eval { @handlers = nil }
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should default to an empty set" do
|
29
|
+
Seam::Worker.all.count.must_equal 0
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should return new instances of all handlers" do
|
33
|
+
instance = Object.new
|
34
|
+
klass = Struct.new(:new).new instance
|
35
|
+
Seam::Worker.inherited klass
|
36
|
+
Seam::Worker.all.count.must_equal 1
|
37
|
+
Seam::Worker.all[0].must_be_same_as instance
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
|
42
|
+
describe "handler for" do
|
43
|
+
|
44
|
+
let(:handler_1) { Struct.new(:handles).new SecureRandom.uuid }
|
45
|
+
let(:handler_2) { Struct.new(:handles).new SecureRandom.uuid }
|
46
|
+
let(:handler_3) { Struct.new(:handles).new SecureRandom.uuid }
|
47
|
+
|
48
|
+
before do
|
49
|
+
handler_1_class, handler_2_class, handler_3_class = Object.new, Object.new, Object.new
|
50
|
+
|
51
|
+
handler_1_class = Struct.new(:new).new handler_1
|
52
|
+
handler_2_class = Struct.new(:new).new handler_2
|
53
|
+
handler_3_class = Struct.new(:new).new handler_3
|
54
|
+
|
55
|
+
Seam::Worker.instance_eval do
|
56
|
+
@handlers = [handler_1_class, handler_2_class, handler_3_class]
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should return the handler for the type" do
|
61
|
+
Seam::Worker.handler_for(handler_2.handles).must_be_same_as handler_2
|
62
|
+
Seam::Worker.handler_for(handler_1.handles).must_be_same_as handler_1
|
63
|
+
Seam::Worker.handler_for(handler_3.handles).must_be_same_as handler_3
|
64
|
+
end
|
65
|
+
|
66
|
+
it "should return nil if none exist" do
|
67
|
+
Seam::Worker.handler_for('test').nil?.must_equal true
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
22
71
|
describe "move_to_next_step" do
|
23
72
|
|
24
73
|
[:date].to_objects {[
|