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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 543d46be1752e9734d13693aac9feffc8723eee0
4
- data.tar.gz: 03d4914f2f692cde520ee6988098e665ba2d80e5
3
+ metadata.gz: 470d51ab2b48b338a7a9c74cf337e1a646d5e757
4
+ data.tar.gz: be8a202ea585bfdc718185e93d7ce3f81605a11e
5
5
  SHA512:
6
- metadata.gz: ac4aaf4de3a8a1a107cad42305b6b3f40f29059c650b0f7055c653d0c7519b6e5719f334f543f9c0c1113f5528c64a8aa3bc4d5b4e79881a463435d425e0eba2
7
- data.tar.gz: 20f606a99d159642d18bc0eefbc47b099de04be5a45264b2059ec008e7391603a81c0cbebcd002eca27a4f96e5556f6755dc2e44375b1a0e9a548a13095efe80
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
- [![Build Status](https://travis-ci.org/ryanfields/carry_out.svg?branch=master)](https://travis-ci.org/ryanfields/carry_out) [![Coverage Status](https://coveralls.io/repos/github/ryanfields/carry_out/badge.svg?branch=master)](https://coveralls.io/github/ryanfields/carry_out?branch=master)
5
+ [![Gem Version](https://badge.fury.io/rb/carry_out.svg)](https://badge.fury.io/rb/carry_out) [![Build Status](https://travis-ci.org/ryanfields/carry_out.svg?branch=master)](https://travis-ci.org/ryanfields/carry_out) [![Coverage Status](https://coveralls.io/repos/github/ryanfields/carry_out/badge.svg?branch=master)](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
- ### Wrapping the Execution Context
140
+ ### Initial Artifacts
141
141
 
142
- Contexts can be "baked into" a plan for purposes such as ensuring files get closed, or keeping the entire plan within a database transaction.
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
- inner_plan = CarryOut.will(SayHello)
194
+ say_hello = CarryOut.will(SayHello)
181
195
 
182
- outer_plan = CarryOut
196
+ plan = CarryOut
183
197
  .will(DisplayBanner)
184
- .then(inner_plan)
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 parameters 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.
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
 
@@ -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 |context|
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 do |context|
23
- execute_internal(Result.new(context), &block)
24
- end)
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
 
@@ -1,8 +1,8 @@
1
1
  module CarryOut
2
2
  class Result
3
3
 
4
- def initialize(hash = nil)
5
- @artifacts = Hash[hash] unless hash.nil?
4
+ def initialize(*args)
5
+ @artifacts = args.compact.reduce(&:merge) || Hash.new
6
6
  end
7
7
 
8
8
  def add(group, object)
@@ -1,3 +1,3 @@
1
1
  module CarryOut
2
- VERSION = "0.2.2"
2
+ VERSION = "0.2.3"
3
3
  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.2.2
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Fields