carry_out 0.2.2 → 0.2.3
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/README.md +21 -7
- data/lib/carry_out/plan.rb +7 -7
- data/lib/carry_out/result.rb +2 -2
- data/lib/carry_out/version.rb +1 -1
- 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: 470d51ab2b48b338a7a9c74cf337e1a646d5e757
|
4
|
+
data.tar.gz: be8a202ea585bfdc718185e93d7ce3f81605a11e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 57f102be31ffdc49a2b846211bc2586a588654b1a3a663b5073ed884cf3a95b81c58ad1b1e9699d0c8baee5fc8ef47f070cebbdb5393cc3f9357db4d85871f88
|
7
|
+
data.tar.gz: 054240040fb465c6ea0e1b8e526c2d7e4a325ad72b373a508e199b42e1fb0035c2ffc713114eefabd2e08687827cb8324898eaeeaa8a104704c82d86171d894c
|
data/README.md
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
CarryOut connects units of logic into workflows. Each unit can extend the DSL with parameter methods. Artifacts and errors are collected as the workflow executes and are returned in a result bundle upon completion.
|
4
4
|
|
5
|
-
[](https://travis-ci.org/ryanfields/carry_out) [](https://coveralls.io/github/ryanfields/carry_out?branch=master)
|
5
|
+
[](https://badge.fury.io/rb/carry_out) [](https://travis-ci.org/ryanfields/carry_out) [](https://coveralls.io/github/ryanfields/carry_out?branch=master)
|
6
6
|
|
7
7
|
## Installation
|
8
8
|
|
@@ -137,9 +137,23 @@ plan.execute do |result|
|
|
137
137
|
end
|
138
138
|
```
|
139
139
|
|
140
|
-
###
|
140
|
+
### Initial Artifacts
|
141
141
|
|
142
|
-
|
142
|
+
`Plan#execute` accepts a hash that will seed the initial result artifacts.
|
143
|
+
|
144
|
+
```ruby
|
145
|
+
plan = CarryOut
|
146
|
+
.will(SayHello)
|
147
|
+
.to { |refs| refs[:name] }
|
148
|
+
|
149
|
+
plan.execute(name: 'John')
|
150
|
+
```
|
151
|
+
|
152
|
+
### Wrapping Execution
|
153
|
+
|
154
|
+
Plan execution can be wrapped for purposes such as ensuring files get closed or to run the plan inside a database transaction. Wrapping also provides an alternative mechanism for injecting initial artifacts into the plan result.
|
155
|
+
|
156
|
+
If `Plan#execute` is passed an initial artifact hash, and a wrapper injects an artifact hash, the two will be merged. The wrapper hash will get priority.
|
143
157
|
|
144
158
|
```ruby
|
145
159
|
class FileContext
|
@@ -177,16 +191,16 @@ Wrapper contexts will always be applied to an entire plan. If a plan has multip
|
|
177
191
|
A plan can be used in place of a `CarryOut::Unit`. This allows plans to be reused as part of larger strategies.
|
178
192
|
|
179
193
|
```ruby
|
180
|
-
|
194
|
+
say_hello = CarryOut.will(SayHello)
|
181
195
|
|
182
|
-
|
196
|
+
plan = CarryOut
|
183
197
|
.will(DisplayBanner)
|
184
|
-
.then(
|
198
|
+
.then(say_hello)
|
185
199
|
```
|
186
200
|
|
187
201
|
Passing a plan to `#then` works similar to passing a `CarryOut::Unit` class or instance. If the `as` option is added, the inner plan's result artifacts will be added to the outer plan's result at the specified key.
|
188
202
|
|
189
|
-
**One caveat to be aware of**: There is no way to specify
|
203
|
+
**One caveat to be aware of**: There is no way to specify initial artifacts for an embedded plan. If an embedded plan depends on an external context, `CarryOut#within` is sufficient to work around this limitation. However, there is currently no way for an inner plan to access an outer plan's artifacts. This is considered a bug and will be fixed in a future release.
|
190
204
|
|
191
205
|
## Motivation
|
192
206
|
|
data/lib/carry_out/plan.rb
CHANGED
@@ -12,19 +12,19 @@ module CarryOut
|
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
|
-
def execute(&block)
|
15
|
+
def execute(context = nil, &block)
|
16
16
|
if @wrapper
|
17
17
|
if @wrapper.respond_to?(:execute)
|
18
|
-
@wrapper.execute do |
|
19
|
-
execute_internal(Result.new(context), &block)
|
18
|
+
@wrapper.execute do |wrapper_context|
|
19
|
+
execute_internal(Result.new(context, wrapper_context), &block)
|
20
20
|
end
|
21
21
|
else
|
22
|
-
@wrapper.call(Proc.new
|
23
|
-
execute_internal(Result.new(context), &block)
|
24
|
-
|
22
|
+
@wrapper.call(Proc.new { |wrapper_context|
|
23
|
+
execute_internal(Result.new(context, wrapper_context), &block)
|
24
|
+
})
|
25
25
|
end
|
26
26
|
else
|
27
|
-
execute_internal(&block)
|
27
|
+
execute_internal(Result.new(context), &block)
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
data/lib/carry_out/result.rb
CHANGED
data/lib/carry_out/version.rb
CHANGED