carry_out 0.2.6 → 0.2.7
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 +15 -12
- data/lib/carry_out/plan_node.rb +23 -6
- data/lib/carry_out/reference.rb +22 -0
- data/lib/carry_out/version.rb +1 -1
- data/lib/carry_out.rb +5 -0
- metadata +3 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 843167a029617226c13a57a276b2fcaa345361d7
|
|
4
|
+
data.tar.gz: 45b888c850b7642fc713c3bbb466d6eddc56ea38
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 181d2e3bd653dd716f659354461aa67c44edc8cb33f02f57f636995dd88c3bfc9a6e8e2030f945e24eb5fad859759c9fdfde76fc28ab0d1335ff8f488f3739cd
|
|
7
|
+
data.tar.gz: 8d3c0141281a011d4575f8af64b6bbcc09ad29fee8138a7241ce5bcca5569d330038bc6d6a172351a6c65026c6426ddefb5d25d00172cc3d6380da56e9d1942a
|
data/README.md
CHANGED
|
@@ -105,7 +105,7 @@ A unit may wish to provide the syntactic sugar while ensuring the underlying ins
|
|
|
105
105
|
|
|
106
106
|
Plan executions return a `CarryOut::Result` object that contains any artifacts returned by units (in `Result#artifacts`), along with any errors raised (in `Result#errors`). If `errors` is empty, `Result#success?` will return `true`.
|
|
107
107
|
|
|
108
|
-
|
|
108
|
+
References via `CarryOut#get` or via blocks can be used to pass result artifacts on to subsequent execution units in the plan.
|
|
109
109
|
|
|
110
110
|
```ruby
|
|
111
111
|
class AddToCart < CarryOut::Unit
|
|
@@ -127,11 +127,12 @@ end
|
|
|
127
127
|
```
|
|
128
128
|
```ruby
|
|
129
129
|
plan = CarryOut
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
130
|
+
.will(AddToCart, as: :cart)
|
|
131
|
+
.items([ item1, item2, item3])
|
|
132
|
+
.then(CalculateSubtotal, as: :invoice)
|
|
133
|
+
.items(CarryOut.get(:cart, :contents)
|
|
134
|
+
# or .items { |refs| refs[:cart][:contents] }
|
|
135
|
+
|
|
135
136
|
plan.execute do |result|
|
|
136
137
|
puts "Subtotal: #{result.artifacts[:invoice][:subtotal]}"
|
|
137
138
|
end
|
|
@@ -144,7 +145,7 @@ end
|
|
|
144
145
|
```ruby
|
|
145
146
|
plan = CarryOut
|
|
146
147
|
.will(SayHello)
|
|
147
|
-
.to
|
|
148
|
+
.to(CarryOut.get(:name))
|
|
148
149
|
|
|
149
150
|
plan.execute(name: 'John')
|
|
150
151
|
```
|
|
@@ -171,7 +172,7 @@ end
|
|
|
171
172
|
plan = CarryOut
|
|
172
173
|
.within(FileContext.new("path/to/file")) # Expects instance, not class
|
|
173
174
|
.will(DoAThing)
|
|
174
|
-
|
|
175
|
+
.with_file(CarryOut.get(:file))
|
|
175
176
|
```
|
|
176
177
|
|
|
177
178
|
The wrapping context can also be a block.
|
|
@@ -208,14 +209,16 @@ Use the `if` or `unless` directive to conditionally execute a unit.
|
|
|
208
209
|
|
|
209
210
|
```ruby
|
|
210
211
|
plan = CarryOut
|
|
211
|
-
|
|
212
|
-
|
|
212
|
+
.will(SayHello)
|
|
213
|
+
.if { |refs| refs[:audible] }
|
|
214
|
+
# or .if(CarryOut.get(:audible))
|
|
213
215
|
```
|
|
214
216
|
|
|
215
217
|
```ruby
|
|
216
218
|
plan = CarryOut
|
|
217
|
-
|
|
218
|
-
|
|
219
|
+
.will(SayHello)
|
|
220
|
+
.unless { |refs| refs[:silenced] }
|
|
221
|
+
# or .unless(CarryOut.get(:silenced))
|
|
219
222
|
```
|
|
220
223
|
|
|
221
224
|
## Motivation
|
data/lib/carry_out/plan_node.rb
CHANGED
|
@@ -8,12 +8,8 @@ module CarryOut
|
|
|
8
8
|
end
|
|
9
9
|
|
|
10
10
|
def method_missing(method, *args, &block)
|
|
11
|
-
if
|
|
12
|
-
|
|
13
|
-
@messages << { method: method, argument: args.first || true, block: block }
|
|
14
|
-
else
|
|
15
|
-
raise NoMethodError.new("#{@unitClass} instances do not respond to `#{method}'", method, *args)
|
|
16
|
-
end
|
|
11
|
+
if is_parameter_method?(*args, &block)
|
|
12
|
+
append_message(method, *args, &block)
|
|
17
13
|
else
|
|
18
14
|
super
|
|
19
15
|
end
|
|
@@ -45,5 +41,26 @@ module CarryOut
|
|
|
45
41
|
def next=(value)
|
|
46
42
|
@next = value.to_sym
|
|
47
43
|
end
|
|
44
|
+
|
|
45
|
+
private
|
|
46
|
+
def append_message(method, *args, &block)
|
|
47
|
+
if @unitClass.instance_methods.include?(method)
|
|
48
|
+
if args.first.kind_of?(Reference)
|
|
49
|
+
if block.nil?
|
|
50
|
+
@messages << { method: method, block: args.first }
|
|
51
|
+
else
|
|
52
|
+
raise ArgumentError.new("References and blocks are mutually exclusive")
|
|
53
|
+
end
|
|
54
|
+
else
|
|
55
|
+
@messages << { method: method, argument: args.first || true, block: block }
|
|
56
|
+
end
|
|
57
|
+
else
|
|
58
|
+
raise NoMethodError.new("#{@unitClass} instances do not respond to `#{method}'", method, *args)
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def is_parameter_method?(*args, &block)
|
|
63
|
+
args.length <= 1 || (args.length == 0 && !block.nil?)
|
|
64
|
+
end
|
|
48
65
|
end
|
|
49
66
|
end
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
module CarryOut
|
|
2
|
+
class Reference
|
|
3
|
+
|
|
4
|
+
def initialize(*args)
|
|
5
|
+
@key_path = args
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def call(context)
|
|
9
|
+
result = context
|
|
10
|
+
@key_path.each do |key|
|
|
11
|
+
if context.respond_to?(:has_key?) && context.has_key?(key)
|
|
12
|
+
result = context[key]
|
|
13
|
+
else
|
|
14
|
+
result = nil
|
|
15
|
+
break
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
result
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
data/lib/carry_out/version.rb
CHANGED
data/lib/carry_out.rb
CHANGED
|
@@ -3,11 +3,16 @@ require "carry_out/version"
|
|
|
3
3
|
require "carry_out/error"
|
|
4
4
|
require "carry_out/plan"
|
|
5
5
|
require "carry_out/plan_node"
|
|
6
|
+
require "carry_out/reference"
|
|
6
7
|
require "carry_out/result"
|
|
7
8
|
require "carry_out/unit"
|
|
8
9
|
require "carry_out/unit_error"
|
|
9
10
|
|
|
10
11
|
module CarryOut
|
|
12
|
+
def self.get(*args)
|
|
13
|
+
Reference.new(*args)
|
|
14
|
+
end
|
|
15
|
+
|
|
11
16
|
def self.will(*args)
|
|
12
17
|
Plan.new(*args)
|
|
13
18
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: carry_out
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.2.
|
|
4
|
+
version: 0.2.7
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Ryan Fields
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2017-03-
|
|
11
|
+
date: 2017-03-26 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|
|
@@ -91,6 +91,7 @@ files:
|
|
|
91
91
|
- lib/carry_out/error.rb
|
|
92
92
|
- lib/carry_out/plan.rb
|
|
93
93
|
- lib/carry_out/plan_node.rb
|
|
94
|
+
- lib/carry_out/reference.rb
|
|
94
95
|
- lib/carry_out/result.rb
|
|
95
96
|
- lib/carry_out/unit.rb
|
|
96
97
|
- lib/carry_out/unit_error.rb
|