flow 0.10.6 → 0.10.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +108 -1249
- data/lib/flow.rb +14 -18
- data/lib/flow/concerns/transaction_wrapper.rb +2 -0
- data/lib/flow/errors.rb +14 -0
- data/lib/flow/flow/trigger.rb +4 -4
- data/lib/flow/flow_base.rb +1 -1
- data/lib/flow/malfunction/base.rb +10 -0
- data/lib/flow/operation/core.rb +1 -1
- data/lib/flow/operation/error_handler.rb +1 -1
- data/lib/flow/operation_base.rb +1 -1
- data/lib/flow/rspec/custom_matchers/have_on_state.rb +6 -1
- data/lib/flow/state_base.rb +1 -1
- data/lib/flow/state_proxy.rb +6 -6
- data/lib/flow/version.rb +1 -1
- metadata +100 -19
data/lib/flow.rb
CHANGED
@@ -1,29 +1,25 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require "active_model"
|
4
|
-
require "active_record"
|
5
4
|
require "active_support"
|
6
5
|
|
7
|
-
require "
|
6
|
+
require "spicerack"
|
7
|
+
require "conjunction"
|
8
|
+
require "malfunction"
|
8
9
|
|
9
|
-
|
10
|
+
require_relative "flow/version"
|
10
11
|
|
11
|
-
|
12
|
+
require_relative "flow/errors"
|
12
13
|
|
13
|
-
|
14
|
-
require "flow/operation_base"
|
15
|
-
require "flow/state_base"
|
16
|
-
require "flow/state_proxy"
|
14
|
+
require_relative "flow/concerns/transaction_wrapper"
|
17
15
|
|
18
|
-
|
19
|
-
class Error < StandardError; end
|
16
|
+
require_relative "flow/malfunction/base"
|
20
17
|
|
21
|
-
|
22
|
-
|
18
|
+
# TODO: Remove inheritance nonsense, just use Substance once deprecation is removed from Spicerack
|
19
|
+
class Flow::RootObject < (defined?(Substance::RootObject) ? Substance::RootObject : Spicerack::RootObject); end
|
20
|
+
class Flow::InputModel < (defined?(Substance::InputModel) ? Substance::InputModel : Spicerack::InputModel); end
|
23
21
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
class NotValidatedError < StateError; end
|
29
|
-
end
|
22
|
+
require_relative "flow/flow_base"
|
23
|
+
require_relative "flow/operation_base"
|
24
|
+
require_relative "flow/state_base"
|
25
|
+
require_relative "flow/state_proxy"
|
data/lib/flow/errors.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Flow
|
4
|
+
class Error < StandardError; end
|
5
|
+
|
6
|
+
class FlowError < Error; end
|
7
|
+
class StateInvalidError < FlowError; end
|
8
|
+
|
9
|
+
class OperationError < Error; end
|
10
|
+
class AlreadyExecutedError < OperationError; end
|
11
|
+
|
12
|
+
class StateError < Error; end
|
13
|
+
class NotValidatedError < StateError; end
|
14
|
+
end
|
data/lib/flow/flow/trigger.rb
CHANGED
@@ -7,12 +7,12 @@ module Flow
|
|
7
7
|
extend ActiveSupport::Concern
|
8
8
|
|
9
9
|
class_methods do
|
10
|
-
def trigger!(*arguments)
|
11
|
-
new(*arguments).trigger!
|
10
|
+
def trigger!(*arguments, **options)
|
11
|
+
new(*arguments, **options).trigger!
|
12
12
|
end
|
13
13
|
|
14
|
-
def trigger(*arguments)
|
15
|
-
new(*arguments).trigger
|
14
|
+
def trigger(*arguments, **options)
|
15
|
+
new(*arguments, **options).trigger
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
data/lib/flow/flow_base.rb
CHANGED
@@ -10,7 +10,7 @@ require_relative "flow/trigger"
|
|
10
10
|
|
11
11
|
# A **Flow** is a collection of procedurally executed **Operations** sharing a common **State**.
|
12
12
|
module Flow
|
13
|
-
class FlowBase <
|
13
|
+
class FlowBase < RootObject
|
14
14
|
include Conjunction::Junction
|
15
15
|
suffixed_with "Flow"
|
16
16
|
|
data/lib/flow/operation/core.rb
CHANGED
@@ -16,7 +16,7 @@ module Flow
|
|
16
16
|
def state_proxy_class
|
17
17
|
@state_proxy_class ||= Class.new(StateProxy).tap do |proxy_class|
|
18
18
|
delegate_method_names = _state_writers.map { |method_name| "#{method_name}=" } + _state_readers
|
19
|
-
proxy_class.delegate(*delegate_method_names, to: :
|
19
|
+
proxy_class.delegate(*delegate_method_names, to: :_state) if delegate_method_names.any?
|
20
20
|
end
|
21
21
|
end
|
22
22
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# When an exception is raised during
|
3
|
+
# When an exception is raised during execution, but a handler can rescue, it causes a failure instead.
|
4
4
|
module Flow
|
5
5
|
module Operation
|
6
6
|
module ErrorHandler
|
data/lib/flow/operation_base.rb
CHANGED
@@ -11,7 +11,7 @@ require_relative "operation/transactions"
|
|
11
11
|
|
12
12
|
# An **Operation** is a service object which is executed with a **State**.
|
13
13
|
module Flow
|
14
|
-
class OperationBase <
|
14
|
+
class OperationBase < RootObject
|
15
15
|
include TransactionWrapper
|
16
16
|
include Operation::Accessors
|
17
17
|
include Operation::Callbacks
|
@@ -44,7 +44,12 @@ module Flow
|
|
44
44
|
|
45
45
|
def matches?(object)
|
46
46
|
@state_expectations.all? do |key, value|
|
47
|
-
|
47
|
+
# If state is actually a StateProxy, we to access the state directly with _state
|
48
|
+
if object.state.respond_to?(:_state, true)
|
49
|
+
expect(object.state.__send__(:_state).public_send(key)).to match value
|
50
|
+
else
|
51
|
+
expect(object.state.public_send(key)).to match value
|
52
|
+
end
|
48
53
|
end
|
49
54
|
end
|
50
55
|
|
data/lib/flow/state_base.rb
CHANGED
data/lib/flow/state_proxy.rb
CHANGED
@@ -4,27 +4,27 @@
|
|
4
4
|
module Flow
|
5
5
|
class StateProxy
|
6
6
|
def initialize(state)
|
7
|
-
@
|
7
|
+
@_state = state
|
8
8
|
end
|
9
9
|
|
10
10
|
# @deprecated
|
11
11
|
def method_missing(method_name, *arguments, &block)
|
12
|
-
return super unless
|
12
|
+
return super unless _state.respond_to?(method_name)
|
13
13
|
|
14
14
|
ActiveSupport::Deprecation.warn(
|
15
|
-
"Direct state access of `#{method_name}' on #{
|
15
|
+
"Direct state access of `#{method_name}' on #{_state.inspect} will be removed in a future version of flow. "\
|
16
16
|
"Use a state accessor instead - for more information see github/freshly/flow/deprecation_notice"
|
17
17
|
)
|
18
|
-
|
18
|
+
_state.public_send(method_name, *arguments, &block)
|
19
19
|
end
|
20
20
|
|
21
21
|
# @deprecated
|
22
22
|
def respond_to_missing?(method_name, include_private = false)
|
23
|
-
|
23
|
+
_state.respond_to?(method_name) || super
|
24
24
|
end
|
25
25
|
|
26
26
|
private
|
27
27
|
|
28
|
-
attr_reader :
|
28
|
+
attr_reader :_state
|
29
29
|
end
|
30
30
|
end
|
data/lib/flow/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: flow
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.10.
|
4
|
+
version: 0.10.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eric Garside
|
@@ -12,7 +12,7 @@ authors:
|
|
12
12
|
autorequire:
|
13
13
|
bindir: bin
|
14
14
|
cert_chain: []
|
15
|
-
date:
|
15
|
+
date: 2021-06-16 00:00:00.000000000 Z
|
16
16
|
dependencies:
|
17
17
|
- !ruby/object:Gem::Dependency
|
18
18
|
name: activemodel
|
@@ -29,7 +29,7 @@ dependencies:
|
|
29
29
|
- !ruby/object:Gem::Version
|
30
30
|
version: 5.2.1
|
31
31
|
- !ruby/object:Gem::Dependency
|
32
|
-
name:
|
32
|
+
name: activesupport
|
33
33
|
requirement: !ruby/object:Gem::Requirement
|
34
34
|
requirements:
|
35
35
|
- - ">="
|
@@ -43,26 +43,92 @@ dependencies:
|
|
43
43
|
- !ruby/object:Gem::Version
|
44
44
|
version: 5.2.1
|
45
45
|
- !ruby/object:Gem::Dependency
|
46
|
-
name:
|
46
|
+
name: spicerack
|
47
47
|
requirement: !ruby/object:Gem::Requirement
|
48
48
|
requirements:
|
49
49
|
- - ">="
|
50
50
|
- !ruby/object:Gem::Version
|
51
|
-
version:
|
51
|
+
version: 0.2.0
|
52
|
+
- - "<"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.0'
|
52
55
|
type: :runtime
|
53
56
|
prerelease: false
|
54
57
|
version_requirements: !ruby/object:Gem::Requirement
|
55
58
|
requirements:
|
56
59
|
- - ">="
|
57
60
|
- !ruby/object:Gem::Version
|
58
|
-
version:
|
61
|
+
version: 0.2.0
|
62
|
+
- - "<"
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: '1.0'
|
65
|
+
- !ruby/object:Gem::Dependency
|
66
|
+
name: conjunction
|
67
|
+
requirement: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: 0.2.0
|
72
|
+
- - "<"
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '1.0'
|
75
|
+
type: :runtime
|
76
|
+
prerelease: false
|
77
|
+
version_requirements: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: 0.2.0
|
82
|
+
- - "<"
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '1.0'
|
85
|
+
- !ruby/object:Gem::Dependency
|
86
|
+
name: short_circu_it
|
87
|
+
requirement: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - ">="
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: 0.2.0
|
92
|
+
- - "<"
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '1.0'
|
95
|
+
type: :runtime
|
96
|
+
prerelease: false
|
97
|
+
version_requirements: !ruby/object:Gem::Requirement
|
98
|
+
requirements:
|
99
|
+
- - ">="
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: 0.2.0
|
102
|
+
- - "<"
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '1.0'
|
105
|
+
- !ruby/object:Gem::Dependency
|
106
|
+
name: technologic
|
107
|
+
requirement: !ruby/object:Gem::Requirement
|
108
|
+
requirements:
|
109
|
+
- - ">="
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: 0.2.0
|
112
|
+
- - "<"
|
113
|
+
- !ruby/object:Gem::Version
|
114
|
+
version: '1.0'
|
115
|
+
type: :runtime
|
116
|
+
prerelease: false
|
117
|
+
version_requirements: !ruby/object:Gem::Requirement
|
118
|
+
requirements:
|
119
|
+
- - ">="
|
120
|
+
- !ruby/object:Gem::Version
|
121
|
+
version: 0.2.0
|
122
|
+
- - "<"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '1.0'
|
59
125
|
- !ruby/object:Gem::Dependency
|
60
|
-
name:
|
126
|
+
name: malfunction
|
61
127
|
requirement: !ruby/object:Gem::Requirement
|
62
128
|
requirements:
|
63
129
|
- - ">="
|
64
130
|
- !ruby/object:Gem::Version
|
65
|
-
version: 0.
|
131
|
+
version: 0.2.0
|
66
132
|
- - "<"
|
67
133
|
- !ruby/object:Gem::Version
|
68
134
|
version: '1.0'
|
@@ -72,22 +138,36 @@ dependencies:
|
|
72
138
|
requirements:
|
73
139
|
- - ">="
|
74
140
|
- !ruby/object:Gem::Version
|
75
|
-
version: 0.
|
141
|
+
version: 0.2.0
|
76
142
|
- - "<"
|
77
143
|
- !ruby/object:Gem::Version
|
78
144
|
version: '1.0'
|
145
|
+
- !ruby/object:Gem::Dependency
|
146
|
+
name: activerecord
|
147
|
+
requirement: !ruby/object:Gem::Requirement
|
148
|
+
requirements:
|
149
|
+
- - ">="
|
150
|
+
- !ruby/object:Gem::Version
|
151
|
+
version: 5.2.1
|
152
|
+
type: :development
|
153
|
+
prerelease: false
|
154
|
+
version_requirements: !ruby/object:Gem::Requirement
|
155
|
+
requirements:
|
156
|
+
- - ">="
|
157
|
+
- !ruby/object:Gem::Version
|
158
|
+
version: 5.2.1
|
79
159
|
- !ruby/object:Gem::Dependency
|
80
160
|
name: bundler
|
81
161
|
requirement: !ruby/object:Gem::Requirement
|
82
162
|
requirements:
|
83
|
-
- - "
|
163
|
+
- - ">="
|
84
164
|
- !ruby/object:Gem::Version
|
85
165
|
version: 2.0.1
|
86
166
|
type: :development
|
87
167
|
prerelease: false
|
88
168
|
version_requirements: !ruby/object:Gem::Requirement
|
89
169
|
requirements:
|
90
|
-
- - "
|
170
|
+
- - ">="
|
91
171
|
- !ruby/object:Gem::Version
|
92
172
|
version: 2.0.1
|
93
173
|
- !ruby/object:Gem::Dependency
|
@@ -96,14 +176,14 @@ dependencies:
|
|
96
176
|
requirements:
|
97
177
|
- - "~>"
|
98
178
|
- !ruby/object:Gem::Version
|
99
|
-
version: '
|
179
|
+
version: '13.0'
|
100
180
|
type: :development
|
101
181
|
prerelease: false
|
102
182
|
version_requirements: !ruby/object:Gem::Requirement
|
103
183
|
requirements:
|
104
184
|
- - "~>"
|
105
185
|
- !ruby/object:Gem::Version
|
106
|
-
version: '
|
186
|
+
version: '13.0'
|
107
187
|
- !ruby/object:Gem::Dependency
|
108
188
|
name: simplecov
|
109
189
|
requirement: !ruby/object:Gem::Requirement
|
@@ -180,7 +260,7 @@ dependencies:
|
|
180
260
|
requirements:
|
181
261
|
- - ">="
|
182
262
|
- !ruby/object:Gem::Version
|
183
|
-
version: 0.
|
263
|
+
version: 0.25.7
|
184
264
|
- - "<"
|
185
265
|
- !ruby/object:Gem::Version
|
186
266
|
version: '1.0'
|
@@ -190,7 +270,7 @@ dependencies:
|
|
190
270
|
requirements:
|
191
271
|
- - ">="
|
192
272
|
- !ruby/object:Gem::Version
|
193
|
-
version: 0.
|
273
|
+
version: 0.25.7
|
194
274
|
- - "<"
|
195
275
|
- !ruby/object:Gem::Version
|
196
276
|
version: '1.0'
|
@@ -200,7 +280,7 @@ dependencies:
|
|
200
280
|
requirements:
|
201
281
|
- - ">="
|
202
282
|
- !ruby/object:Gem::Version
|
203
|
-
version: 0.
|
283
|
+
version: 0.21.0
|
204
284
|
- - "<"
|
205
285
|
- !ruby/object:Gem::Version
|
206
286
|
version: '1.0'
|
@@ -210,7 +290,7 @@ dependencies:
|
|
210
290
|
requirements:
|
211
291
|
- - ">="
|
212
292
|
- !ruby/object:Gem::Version
|
213
|
-
version: 0.
|
293
|
+
version: 0.21.0
|
214
294
|
- - "<"
|
215
295
|
- !ruby/object:Gem::Version
|
216
296
|
version: '1.0'
|
@@ -226,6 +306,7 @@ files:
|
|
226
306
|
- README.md
|
227
307
|
- lib/flow.rb
|
228
308
|
- lib/flow/concerns/transaction_wrapper.rb
|
309
|
+
- lib/flow/errors.rb
|
229
310
|
- lib/flow/flow/callbacks.rb
|
230
311
|
- lib/flow/flow/core.rb
|
231
312
|
- lib/flow/flow/flux.rb
|
@@ -234,6 +315,7 @@ files:
|
|
234
315
|
- lib/flow/flow/transactions.rb
|
235
316
|
- lib/flow/flow/trigger.rb
|
236
317
|
- lib/flow/flow_base.rb
|
318
|
+
- lib/flow/malfunction/base.rb
|
237
319
|
- lib/flow/operation/accessors.rb
|
238
320
|
- lib/flow/operation/callbacks.rb
|
239
321
|
- lib/flow/operation/core.rb
|
@@ -320,8 +402,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
320
402
|
- !ruby/object:Gem::Version
|
321
403
|
version: '0'
|
322
404
|
requirements: []
|
323
|
-
|
324
|
-
rubygems_version: 2.7.6
|
405
|
+
rubygems_version: 3.2.17
|
325
406
|
signing_key:
|
326
407
|
specification_version: 4
|
327
408
|
summary: Write modular and reusable business logic that's understandable and maintainable.
|