flow 0.10.7.1 → 0.11.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/flow/concerns/transaction_wrapper.rb +2 -0
- data/lib/flow/errors.rb +14 -0
- data/lib/flow/flow_base.rb +1 -1
- data/lib/flow/operation/accessors.rb +23 -25
- data/lib/flow/operation/core.rb +1 -1
- data/lib/flow/operation_base.rb +1 -1
- data/lib/flow/rspec/custom_matchers/have_on_state.rb +1 -1
- data/lib/flow/spec_helper.rb +1 -1
- data/lib/flow/state_base.rb +1 -7
- data/lib/flow/version.rb +1 -1
- data/lib/flow.rb +10 -21
- metadata +75 -16
- data/lib/flow/state/output.rb +0 -59
- data/lib/flow/state/status.rb +0 -22
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b58b685f68376d3cbb4e00e869d9f1a16d15ffb74fe13ed9c8088c89b5b915ca
|
4
|
+
data.tar.gz: 0a9028c03e0c7196f4feb4a2744f00262d3b2799e8752a87e95484a0344d47ef
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9749b0bbbcb7a59ff426c81d0a1e5c05a913a383752afc641d8c90679b24f9a572873ad8efc9e7abaac8f19664f1b5e5e8b7474a71ab88f63abe04fcd1ba5bfa
|
7
|
+
data.tar.gz: ef93d1bd2d6e73f417daebb0c6884fb323677a9ff322eb7be8577506ce75c5b0596a161a56e716b18f049dc3c0625488f90995b00218ce2c648f9d91a10f73e1
|
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_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 < Substance::RootObject
|
14
14
|
include Conjunction::Junction
|
15
15
|
suffixed_with "Flow"
|
16
16
|
|
@@ -1,58 +1,56 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require "set"
|
4
|
+
|
3
5
|
module Flow
|
4
6
|
module Operation
|
5
7
|
module Accessors
|
6
8
|
extend ActiveSupport::Concern
|
7
9
|
|
8
10
|
included do
|
9
|
-
class_attribute :_state_readers, instance_writer: false, default:
|
10
|
-
class_attribute :_state_writers, instance_writer: false, default:
|
11
|
-
class_attribute :_state_accessors, instance_writer: false, default:
|
11
|
+
class_attribute :_state_readers, instance_writer: false, default: Set.new
|
12
|
+
class_attribute :_state_writers, instance_writer: false, default: Set.new
|
13
|
+
class_attribute :_state_accessors, instance_writer: false, default: Set.new
|
12
14
|
end
|
13
15
|
|
14
|
-
|
16
|
+
module ClassMethods
|
15
17
|
protected
|
16
18
|
|
17
|
-
def state_reader(
|
18
|
-
|
19
|
+
def state_reader(*names, prefix: false)
|
20
|
+
names.each do |name|
|
21
|
+
delegate name, prefix: prefix, to: :state
|
19
22
|
|
20
|
-
|
23
|
+
_add_state_reader_tracker(name.to_sym)
|
24
|
+
end
|
21
25
|
end
|
22
26
|
|
23
|
-
def state_writer(
|
24
|
-
|
27
|
+
def state_writer(*names, prefix: false)
|
28
|
+
names.each do |name|
|
29
|
+
delegate "#{name}=", prefix: prefix, to: :state
|
25
30
|
|
26
|
-
|
31
|
+
_add_state_writer_tracker(name.to_sym)
|
32
|
+
end
|
27
33
|
end
|
28
34
|
|
29
|
-
def state_accessor(
|
30
|
-
|
31
|
-
|
35
|
+
def state_accessor(*names, prefix: false)
|
36
|
+
names.each do |name|
|
37
|
+
state_reader name, prefix: prefix
|
38
|
+
state_writer name, prefix: prefix
|
39
|
+
end
|
32
40
|
end
|
33
41
|
|
34
42
|
private
|
35
43
|
|
36
44
|
def _add_state_reader_tracker(name)
|
37
|
-
|
38
|
-
|
39
|
-
_add_state_accessor_tracker(name) if _state_writers.include?(name)
|
45
|
+
_state_accessors << name if _state_writers.include?(name)
|
40
46
|
_state_readers << name
|
41
47
|
end
|
42
48
|
|
43
49
|
def _add_state_writer_tracker(name)
|
44
|
-
|
45
|
-
|
46
|
-
_add_state_accessor_tracker(name) if _state_readers.include?(name)
|
50
|
+
_state_accessors << name if _state_readers.include?(name)
|
47
51
|
_state_writers << name
|
48
52
|
end
|
49
53
|
|
50
|
-
def _add_state_accessor_tracker(name)
|
51
|
-
return if _state_accessors.include?(name)
|
52
|
-
|
53
|
-
_state_accessors << name
|
54
|
-
end
|
55
|
-
|
56
54
|
def inherited(base)
|
57
55
|
base._state_readers = _state_readers.dup
|
58
56
|
base._state_writers = _state_writers.dup
|
data/lib/flow/operation/core.rb
CHANGED
@@ -15,7 +15,7 @@ module Flow
|
|
15
15
|
class_methods do
|
16
16
|
def state_proxy_class
|
17
17
|
@state_proxy_class ||= Class.new(StateProxy).tap do |proxy_class|
|
18
|
-
delegate_method_names = _state_writers.map { |method_name| "#{method_name}=" } + _state_readers
|
18
|
+
delegate_method_names = _state_writers.map { |method_name| "#{method_name}=" } + _state_readers.to_a
|
19
19
|
proxy_class.delegate(*delegate_method_names, to: :_state) if delegate_method_names.any?
|
20
20
|
end
|
21
21
|
end
|
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 < Substance::RootObject
|
15
15
|
include TransactionWrapper
|
16
16
|
include Operation::Accessors
|
17
17
|
include Operation::Callbacks
|
@@ -45,7 +45,7 @@ module Flow
|
|
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)
|
48
|
+
if object.state.respond_to?(:_state, true)
|
49
49
|
expect(object.state.__send__(:_state).public_send(key)).to match value
|
50
50
|
else
|
51
51
|
expect(object.state.public_send(key)).to match value
|
data/lib/flow/spec_helper.rb
CHANGED
data/lib/flow/state_base.rb
CHANGED
@@ -1,15 +1,9 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative "state/status"
|
4
|
-
require_relative "state/output"
|
5
|
-
|
6
3
|
# A **State** is an aggregation of input and derived data.
|
7
4
|
module Flow
|
8
|
-
class StateBase <
|
5
|
+
class StateBase < Substance::OutputObject
|
9
6
|
include Conjunction::Junction
|
10
7
|
suffixed_with "State"
|
11
|
-
|
12
|
-
include State::Status
|
13
|
-
include State::Output
|
14
8
|
end
|
15
9
|
end
|
data/lib/flow/version.rb
CHANGED
data/lib/flow.rb
CHANGED
@@ -1,32 +1,21 @@
|
|
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 "conjunction"
|
8
7
|
require "malfunction"
|
8
|
+
require "substance"
|
9
9
|
|
10
|
-
|
10
|
+
require_relative "flow/version"
|
11
11
|
|
12
|
-
|
12
|
+
require_relative "flow/errors"
|
13
13
|
|
14
|
-
|
14
|
+
require_relative "flow/concerns/transaction_wrapper"
|
15
15
|
|
16
|
-
|
17
|
-
require "flow/operation_base"
|
18
|
-
require "flow/state_base"
|
19
|
-
require "flow/state_proxy"
|
16
|
+
require_relative "flow/malfunction/base"
|
20
17
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
class StateInvalidError < FlowError; end
|
26
|
-
|
27
|
-
class OperationError < Error; end
|
28
|
-
class AlreadyExecutedError < OperationError; end
|
29
|
-
|
30
|
-
class StateError < Error; end
|
31
|
-
class NotValidatedError < StateError; end
|
32
|
-
end
|
18
|
+
require_relative "flow/flow_base"
|
19
|
+
require_relative "flow/operation_base"
|
20
|
+
require_relative "flow/state_base"
|
21
|
+
require_relative "flow/state_proxy"
|
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.
|
4
|
+
version: 0.11.0
|
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: 2021-
|
15
|
+
date: 2021-09-01 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,32 @@ dependencies:
|
|
43
43
|
- !ruby/object:Gem::Version
|
44
44
|
version: 5.2.1
|
45
45
|
- !ruby/object:Gem::Dependency
|
46
|
-
name:
|
46
|
+
name: conjunction
|
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'
|
59
65
|
- !ruby/object:Gem::Dependency
|
60
|
-
name:
|
66
|
+
name: short_circu_it
|
61
67
|
requirement: !ruby/object:Gem::Requirement
|
62
68
|
requirements:
|
63
69
|
- - ">="
|
64
70
|
- !ruby/object:Gem::Version
|
65
|
-
version: 0.
|
71
|
+
version: 0.2.0
|
66
72
|
- - "<"
|
67
73
|
- !ruby/object:Gem::Version
|
68
74
|
version: '1.0'
|
@@ -72,7 +78,47 @@ dependencies:
|
|
72
78
|
requirements:
|
73
79
|
- - ">="
|
74
80
|
- !ruby/object:Gem::Version
|
75
|
-
version: 0.
|
81
|
+
version: 0.2.0
|
82
|
+
- - "<"
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '1.0'
|
85
|
+
- !ruby/object:Gem::Dependency
|
86
|
+
name: substance
|
87
|
+
requirement: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - ">="
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: 0.26.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.26.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
|
76
122
|
- - "<"
|
77
123
|
- !ruby/object:Gem::Version
|
78
124
|
version: '1.0'
|
@@ -96,6 +142,20 @@ dependencies:
|
|
96
142
|
- - "<"
|
97
143
|
- !ruby/object:Gem::Version
|
98
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
|
99
159
|
- !ruby/object:Gem::Dependency
|
100
160
|
name: bundler
|
101
161
|
requirement: !ruby/object:Gem::Requirement
|
@@ -184,16 +244,16 @@ dependencies:
|
|
184
244
|
name: shoulda-matchers
|
185
245
|
requirement: !ruby/object:Gem::Requirement
|
186
246
|
requirements:
|
187
|
-
- -
|
247
|
+
- - "~>"
|
188
248
|
- !ruby/object:Gem::Version
|
189
|
-
version: 4.0
|
249
|
+
version: '4.0'
|
190
250
|
type: :development
|
191
251
|
prerelease: false
|
192
252
|
version_requirements: !ruby/object:Gem::Requirement
|
193
253
|
requirements:
|
194
|
-
- -
|
254
|
+
- - "~>"
|
195
255
|
- !ruby/object:Gem::Version
|
196
|
-
version: 4.0
|
256
|
+
version: '4.0'
|
197
257
|
- !ruby/object:Gem::Dependency
|
198
258
|
name: rspice
|
199
259
|
requirement: !ruby/object:Gem::Requirement
|
@@ -246,6 +306,7 @@ files:
|
|
246
306
|
- README.md
|
247
307
|
- lib/flow.rb
|
248
308
|
- lib/flow/concerns/transaction_wrapper.rb
|
309
|
+
- lib/flow/errors.rb
|
249
310
|
- lib/flow/flow/callbacks.rb
|
250
311
|
- lib/flow/flow/core.rb
|
251
312
|
- lib/flow/flow/flux.rb
|
@@ -279,8 +340,6 @@ files:
|
|
279
340
|
- lib/flow/rspec/shared_contexts/with_failing_operation.rb
|
280
341
|
- lib/flow/rspec/shoulda_matcher_helper.rb
|
281
342
|
- lib/flow/spec_helper.rb
|
282
|
-
- lib/flow/state/output.rb
|
283
|
-
- lib/flow/state/status.rb
|
284
343
|
- lib/flow/state_base.rb
|
285
344
|
- lib/flow/state_proxy.rb
|
286
345
|
- lib/flow/version.rb
|
@@ -341,7 +400,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
341
400
|
- !ruby/object:Gem::Version
|
342
401
|
version: '0'
|
343
402
|
requirements: []
|
344
|
-
rubygems_version: 3.
|
403
|
+
rubygems_version: 3.2.25
|
345
404
|
signing_key:
|
346
405
|
specification_version: 4
|
347
406
|
summary: Write modular and reusable business logic that's understandable and maintainable.
|
data/lib/flow/state/output.rb
DELETED
@@ -1,59 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# Output data is created by Operations during runtime and CANNOT be validated or provided as part of the input.
|
4
|
-
module Flow
|
5
|
-
module State
|
6
|
-
module Output
|
7
|
-
extend ActiveSupport::Concern
|
8
|
-
|
9
|
-
included do
|
10
|
-
class_attribute :_outputs, instance_writer: false, default: []
|
11
|
-
|
12
|
-
delegate :_outputs, to: :class
|
13
|
-
|
14
|
-
after_validation do
|
15
|
-
next unless validated?
|
16
|
-
|
17
|
-
_outputs.each do |key|
|
18
|
-
public_send("#{key}=".to_sym, _defaults[key].value) if _defaults.key?(key) && public_send(key).nil?
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
class_methods do
|
24
|
-
def inherited(base)
|
25
|
-
base._outputs = _outputs.dup
|
26
|
-
super
|
27
|
-
end
|
28
|
-
|
29
|
-
private
|
30
|
-
|
31
|
-
def output(output, default: nil, &block)
|
32
|
-
_outputs << output
|
33
|
-
define_attribute output
|
34
|
-
define_default output, static: default, &block
|
35
|
-
ensure_validation_before output
|
36
|
-
ensure_validation_before "#{output}=".to_sym
|
37
|
-
end
|
38
|
-
|
39
|
-
def ensure_validation_before(method)
|
40
|
-
around_method method do |*arguments|
|
41
|
-
raise NotValidatedError unless validated?
|
42
|
-
|
43
|
-
super(*arguments)
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
def outputs
|
49
|
-
return {} if _outputs.empty?
|
50
|
-
|
51
|
-
output_struct.new(*_outputs.map(&method(:public_send)))
|
52
|
-
end
|
53
|
-
|
54
|
-
def output_struct
|
55
|
-
Struct.new(*_outputs)
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
data/lib/flow/state/status.rb
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# The State status is used to ensure and enforce internal consistency.
|
4
|
-
module Flow
|
5
|
-
module State
|
6
|
-
module Status
|
7
|
-
extend ActiveSupport::Concern
|
8
|
-
|
9
|
-
included do
|
10
|
-
after_validation { self.was_validated = errors.empty? }
|
11
|
-
|
12
|
-
private
|
13
|
-
|
14
|
-
attr_accessor :was_validated
|
15
|
-
end
|
16
|
-
|
17
|
-
def validated?
|
18
|
-
was_validated.present?
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|