carry_out 0.1.4 → 0.2.1
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/carry_out/plan.rb +48 -28
- data/lib/carry_out/plan_node.rb +4 -4
- data/lib/carry_out/result.rb +19 -7
- data/lib/carry_out/unit.rb +1 -1
- data/lib/carry_out/version.rb +1 -1
- data/lib/carry_out.rb +4 -1
- metadata +1 -2
- data/lib/carry_out/result_manipulator.rb +0 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2527666eec64444e35bf101c6b084c6a4397a20b
|
4
|
+
data.tar.gz: da3bd9e8d2f51dbbb758d99565858f2cd9aeb5ce
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 25154eb134c0f970e4f23fe896278b94a87a68fc5edb1e8836a87a37b94f9226fe76da2a8b39283b2853591969eae5f111912c93c7e30ff35d761bac50f91e9f
|
7
|
+
data.tar.gz: 8e088f4e96b57d1f7cc80548cdfe764c72d29f8c9ee63411492b09d8ab0407ba49697f7357d579f0115e5c6d92233bc9c510025f28499438742d1e8d64c79d98
|
data/lib/carry_out/plan.rb
CHANGED
@@ -3,8 +3,9 @@ module CarryOut
|
|
3
3
|
|
4
4
|
def initialize(unit = nil, options = {})
|
5
5
|
@nodes = {}
|
6
|
+
@node_meta = {}
|
6
7
|
@previously_added_node = nil
|
7
|
-
@
|
8
|
+
@wrapper = options[:within]
|
8
9
|
|
9
10
|
unless unit.nil?
|
10
11
|
self.then(unit, options)
|
@@ -12,27 +13,25 @@ module CarryOut
|
|
12
13
|
end
|
13
14
|
|
14
15
|
def execute(&block)
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
while node = @nodes[label] do
|
20
|
-
begin
|
21
|
-
node.execute(ResultManipulator.new(result, label), result.artifacts)
|
22
|
-
rescue UnitError => error
|
23
|
-
result.add(label, CarryOut::Error.new(error.error.message, error.error))
|
24
|
-
break
|
16
|
+
if @wrapper
|
17
|
+
if @wrapper.respond_to?(:execute)
|
18
|
+
@wrapper.execute do |context|
|
19
|
+
execute_internal(Result.new(context), &block)
|
25
20
|
end
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
unless block.nil?
|
31
|
-
block.call(result)
|
21
|
+
else
|
22
|
+
@wrapper.call(Proc.new do |context|
|
23
|
+
execute_internal(Result.new(context), &block)
|
24
|
+
end)
|
32
25
|
end
|
26
|
+
else
|
27
|
+
execute_internal(&block)
|
33
28
|
end
|
34
29
|
end
|
35
30
|
|
31
|
+
def will(*args)
|
32
|
+
self.then(*args)
|
33
|
+
end
|
34
|
+
|
36
35
|
def then(unit, options = {})
|
37
36
|
add_node(PlanNode.new(unit), options[:as])
|
38
37
|
self
|
@@ -53,22 +52,43 @@ module CarryOut
|
|
53
52
|
|
54
53
|
private
|
55
54
|
def add_node(node, as = nil)
|
56
|
-
|
57
|
-
|
58
|
-
if as.nil?
|
59
|
-
until @nodes[label].nil?
|
60
|
-
label = generate_node_name
|
61
|
-
end
|
62
|
-
end
|
55
|
+
id = generate_node_name
|
63
56
|
|
64
|
-
|
65
|
-
@
|
57
|
+
if @previously_added_node.nil?
|
58
|
+
@initial_node_key = id
|
59
|
+
else
|
60
|
+
@previously_added_node.next = id
|
66
61
|
end
|
67
62
|
|
68
|
-
@nodes[
|
63
|
+
@nodes[id] = node
|
64
|
+
@node_meta[id] = { as: as }
|
69
65
|
@previously_added_node = node
|
70
66
|
|
71
|
-
|
67
|
+
id
|
68
|
+
end
|
69
|
+
|
70
|
+
def execute_internal(result = nil, &block)
|
71
|
+
id = @initial_node_key
|
72
|
+
|
73
|
+
(result || Result.new).tap do |result|
|
74
|
+
while node = @nodes[id] do
|
75
|
+
publish_to = @node_meta[id][:as]
|
76
|
+
|
77
|
+
begin
|
78
|
+
node_result = node.execute(result.artifacts)
|
79
|
+
result.add(publish_to, node_result) unless publish_to.nil?
|
80
|
+
rescue UnitError => error
|
81
|
+
result.add(publish_to || id, CarryOut::Error.new(error.error.message, error.error))
|
82
|
+
break
|
83
|
+
end
|
84
|
+
|
85
|
+
id = node.next
|
86
|
+
end
|
87
|
+
|
88
|
+
unless block.nil?
|
89
|
+
block.call(result)
|
90
|
+
end
|
91
|
+
end
|
72
92
|
end
|
73
93
|
|
74
94
|
def generate_node_name
|
data/lib/carry_out/plan_node.rb
CHANGED
@@ -27,16 +27,16 @@ module CarryOut
|
|
27
27
|
@unitClass.instance_methods.include?(method) || super
|
28
28
|
end
|
29
29
|
|
30
|
-
def execute(
|
31
|
-
unit = @unitClass.new
|
30
|
+
def execute(context)
|
31
|
+
unit = @unitClass.respond_to?(:execute) ? @unitClass : @unitClass.new
|
32
32
|
|
33
33
|
@messages.each do |message|
|
34
|
-
arg = message[:block] ? message[:block].call(
|
34
|
+
arg = message[:block] ? message[:block].call(context) : message[:argument]
|
35
35
|
unit.send(message[:method], arg)
|
36
36
|
end
|
37
37
|
|
38
38
|
begin
|
39
|
-
unit.execute
|
39
|
+
unit.execute
|
40
40
|
rescue StandardError => error
|
41
41
|
raise UnitError.new(error)
|
42
42
|
end
|
data/lib/carry_out/result.rb
CHANGED
@@ -1,14 +1,22 @@
|
|
1
1
|
module CarryOut
|
2
2
|
class Result
|
3
3
|
|
4
|
-
def
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
4
|
+
def initialize(hash = nil)
|
5
|
+
@artifacts = Hash[hash] unless hash.nil?
|
6
|
+
end
|
7
|
+
|
8
|
+
def add(group, object)
|
9
|
+
if object.kind_of?(CarryOut::Error)
|
10
|
+
add_error(group, object)
|
11
|
+
elsif object.kind_of?(Result)
|
12
|
+
add(group, object.to_hash)
|
13
|
+
elsif object.kind_of?(Hash)
|
14
|
+
artifacts[group] ||= {}
|
15
|
+
object.each { |k,v| artifacts[group][k] = v }
|
16
|
+
elsif !artifacts[group].nil?
|
17
|
+
artifacts[group] = [ artifacts[group], object ].flatten
|
10
18
|
else
|
11
|
-
artifacts[group] =
|
19
|
+
artifacts[group] = object
|
12
20
|
end
|
13
21
|
end
|
14
22
|
|
@@ -24,6 +32,10 @@ module CarryOut
|
|
24
32
|
@errors.nil? || @errors.empty?
|
25
33
|
end
|
26
34
|
|
35
|
+
def to_hash
|
36
|
+
artifacts
|
37
|
+
end
|
38
|
+
|
27
39
|
private
|
28
40
|
def add_error(group, error)
|
29
41
|
group = errors[group] ||= []
|
data/lib/carry_out/unit.rb
CHANGED
data/lib/carry_out/version.rb
CHANGED
data/lib/carry_out.rb
CHANGED
@@ -4,7 +4,6 @@ require "carry_out/error"
|
|
4
4
|
require "carry_out/plan"
|
5
5
|
require "carry_out/plan_node"
|
6
6
|
require "carry_out/result"
|
7
|
-
require "carry_out/result_manipulator"
|
8
7
|
require "carry_out/unit"
|
9
8
|
require "carry_out/unit_error"
|
10
9
|
|
@@ -12,4 +11,8 @@ module CarryOut
|
|
12
11
|
def self.will(*args)
|
13
12
|
Plan.new(*args)
|
14
13
|
end
|
14
|
+
|
15
|
+
def self.within(unit = nil, &block)
|
16
|
+
Plan.new(nil, within: unit || block)
|
17
|
+
end
|
15
18
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: carry_out
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryan Fields
|
@@ -92,7 +92,6 @@ files:
|
|
92
92
|
- lib/carry_out/plan.rb
|
93
93
|
- lib/carry_out/plan_node.rb
|
94
94
|
- lib/carry_out/result.rb
|
95
|
-
- lib/carry_out/result_manipulator.rb
|
96
95
|
- lib/carry_out/unit.rb
|
97
96
|
- lib/carry_out/unit_error.rb
|
98
97
|
- lib/carry_out/version.rb
|