carry_out 0.2.5 → 0.2.6

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,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- MjE4NTNlZDZmZWRiYTE0NjM5N2IzYzJiMzZhNTg4MTM4YmEyMTUzNQ==
5
- data.tar.gz: !binary |-
6
- ZTVjYjZiZDgxZDRkZTQ2MWNiYjExZmNkYTI3Y2Q3YzQ3YWI0NjkxNg==
2
+ SHA1:
3
+ metadata.gz: 97d5a6e2a244532804c0d40120e5e77830799af7
4
+ data.tar.gz: cf7c9b3f5b5bf11ab0a154899b6d94ebc688b240
7
5
  SHA512:
8
- metadata.gz: !binary |-
9
- OGIyZDgzYTJmNDQyNDQ4MTYzODEyNWNiNGFjMTgzMzcwODIyMDRkZWFhYjQx
10
- MmY4NWI5M2I0M2EyODRmZTkyNzYxMTJjZWJjMDgzNzliOTRlMDI0YmRmMzJh
11
- YmRiNjc2YjQxMGEwZWIwNDI1NmM0NDAwZTk0ZmIzYzE2ZmExYjA=
12
- data.tar.gz: !binary |-
13
- OTM3MjE5ZTRjMDkwZjQzODk1NGUwOGJkYTA4ZDU0OGY0MzFlYWM2NGNlYTJi
14
- OTVhOWI4NjVjYTBhYTM0MjRlNDRkOGY1ZGFlMTc3Mjg1MzM0ZDI1OWExY2Q0
15
- NWI1NGJhZWZhYjUzNWFmNDEwMGQ4ZjQ4ZjUxMjBhMDI1ZmM2M2M=
6
+ metadata.gz: 7c731815764352c2d284f02274aed7d0a926e45990e48326f6969068bbeacbc2b150047167c6c766746483a1239fa263c73f7c8aa21327d79e32b72bd4b54c0a
7
+ data.tar.gz: 60d00e1d0e4aee269bd15e1fbf967cb059a0de2a230d18c82fa0920add98dae0c5fbb4792122d1755d915c3f920a4accb2264153cdb562a24721defb10ce2f93
data/.travis.yml CHANGED
@@ -3,3 +3,7 @@ language: ruby
3
3
  rvm:
4
4
  - 2.3.1
5
5
  before_install: gem install bundler -v 1.12.5
6
+ notifications:
7
+ email:
8
+ on_success: never
9
+ on_failure: change
data/README.md CHANGED
@@ -202,6 +202,22 @@ Passing a plan to `#then` works similar to passing a `CarryOut::Unit` class or i
202
202
 
203
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.
204
204
 
205
+ ### Conditional Units
206
+
207
+ Use the `if` or `unless` directive to conditionally execute a unit.
208
+
209
+ ```ruby
210
+ plan = CarryOut
211
+ .will(SayHello)
212
+ .if { |refs| refs[:audible] }
213
+ ```
214
+
215
+ ```ruby
216
+ plan = CarryOut
217
+ .will(SayHello)
218
+ .unless { |refs| refs[:silenced] }
219
+ ```
220
+
205
221
  ## Motivation
206
222
 
207
223
  I've been trying to keep my Rails controllers clean, but I prefer to avoid shoving inter-model business logic inside database models. The recommendation I most frequently run into is to move that kind of logic into something akin to service objects. I like that idea, but I want to keep my services small and composable, and I want to separate the "what" from the "how" of my logic.
@@ -28,6 +28,15 @@ module CarryOut
28
28
  end
29
29
  end
30
30
 
31
+ def if(&block)
32
+ raise NoMethodError("Conditional execution must be applied to a unit") unless @previously_added_node
33
+
34
+ guards = node_meta(@previously_added_node)[:guards] ||= []
35
+ guards << block
36
+
37
+ self
38
+ end
39
+
31
40
  def will(*args)
32
41
  self.then(*args)
33
42
  end
@@ -37,6 +46,12 @@ module CarryOut
37
46
  self
38
47
  end
39
48
 
49
+ def unless(&block)
50
+ self.if { |refs| !block.call(refs) }
51
+
52
+ self
53
+ end
54
+
40
55
  def method_missing(method, *args, &block)
41
56
  if @previously_added_node
42
57
  @previously_added_node.send(method, *args, &block)
@@ -71,16 +86,8 @@ module CarryOut
71
86
  id = @initial_node_key
72
87
 
73
88
  until (node = @nodes[id]).nil? do
74
- publish_to = @node_meta[id][:as]
75
-
76
- begin
77
- node_result = node.execute(result.artifacts)
78
- result.add(publish_to, node_result) unless publish_to.nil?
79
- rescue UnitError => error
80
- result.add(publish_to || id, CarryOut::Error.new(error.error.message, error.error))
81
- break
82
- end
83
-
89
+ execute_node(node, result) if guard_node(node, result.artifacts)
90
+ break unless result.success?
84
91
  id = node.next
85
92
  end
86
93
 
@@ -91,10 +98,31 @@ module CarryOut
91
98
  result
92
99
  end
93
100
 
101
+ def execute_node(node, result)
102
+ meta = node_meta(node)
103
+ publish_to = meta[:as]
104
+
105
+ begin
106
+ node_result = node.execute(result.artifacts)
107
+ result.add(publish_to, node_result) unless publish_to.nil?
108
+ rescue UnitError => error
109
+ result.add(publish_to || id, CarryOut::Error.new(error.error.message, error.error))
110
+ end
111
+ end
112
+
94
113
  def generate_node_name
95
114
  id = @next_node_id ||= 1
96
115
  @next_node_id += 1
97
116
  "node_#{id}".to_sym
98
117
  end
118
+
119
+ def guard_node(node, artifacts)
120
+ guards = node_meta(node)[:guards]
121
+ guards.nil? || guards.map { |guard| guard.call(artifacts) }.all?
122
+ end
123
+
124
+ def node_meta(node)
125
+ @node_meta[@nodes.key(node)]
126
+ end
99
127
  end
100
128
  end
@@ -1,3 +1,3 @@
1
1
  module CarryOut
2
- VERSION = "0.2.5"
2
+ VERSION = "0.2.6"
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.5
4
+ version: 0.2.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Fields
@@ -14,70 +14,71 @@ dependencies:
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.12'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.12'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ~>
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
33
  version: '10.0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ~>
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '10.0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: minitest
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ~>
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
47
  version: '5.0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ~>
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '5.0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: coveralls
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ! '>='
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ! '>='
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
- description: ! " CarryOut connects units of logic into workflows. Each unit can
70
- extend\n the DSL with parameter methods. Artifacts and errors are collected
71
- as\n the workflow executes and are returned in a result bundle upon completion.\n"
69
+ description: |2
70
+ CarryOut connects units of logic into workflows. Each unit can extend
71
+ the DSL with parameter methods. Artifacts and errors are collected as
72
+ the workflow executes and are returned in a result bundle upon completion.
72
73
  email:
73
74
  - ryan.fields@twoleftbeats.com
74
75
  executables: []
75
76
  extensions: []
76
77
  extra_rdoc_files: []
77
78
  files:
78
- - .coveralls.yml
79
- - .gitignore
80
- - .travis.yml
79
+ - ".coveralls.yml"
80
+ - ".gitignore"
81
+ - ".travis.yml"
81
82
  - CODE_OF_CONDUCT.md
82
83
  - Gemfile
83
84
  - LICENSE.txt
@@ -104,17 +105,17 @@ require_paths:
104
105
  - lib
105
106
  required_ruby_version: !ruby/object:Gem::Requirement
106
107
  requirements:
107
- - - ~>
108
+ - - "~>"
108
109
  - !ruby/object:Gem::Version
109
110
  version: '2.0'
110
111
  required_rubygems_version: !ruby/object:Gem::Requirement
111
112
  requirements:
112
- - - ! '>='
113
+ - - ">="
113
114
  - !ruby/object:Gem::Version
114
115
  version: '0'
115
116
  requirements: []
116
117
  rubyforge_project:
117
- rubygems_version: 2.4.8
118
+ rubygems_version: 2.6.6
118
119
  signing_key:
119
120
  specification_version: 4
120
121
  summary: Compose units of logic into an executable workflow.