flow 0.10.6 → 0.10.9

Sign up to get free protection for your applications and to get access to all the features.
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 "spicery"
6
+ require "spicerack"
7
+ require "conjunction"
8
+ require "malfunction"
8
9
 
9
- require "flow/version"
10
+ require_relative "flow/version"
10
11
 
11
- require "flow/concerns/transaction_wrapper"
12
+ require_relative "flow/errors"
12
13
 
13
- require "flow/flow_base"
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
- module Flow
19
- class Error < StandardError; end
16
+ require_relative "flow/malfunction/base"
20
17
 
21
- class FlowError < Error; end
22
- class StateInvalidError < FlowError; end
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
- class OperationError < Error; end
25
- class AlreadyExecutedError < OperationError; end
26
-
27
- class StateError < Error; end
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"
@@ -7,6 +7,8 @@ module Flow
7
7
 
8
8
  class_methods do
9
9
  def transaction_provider
10
+ raise TransactionProviderNotDefined, "must explicitly define a transaction provider if ActiveRecord is not available" unless defined?(ActiveRecord)
11
+
10
12
  ActiveRecord::Base
11
13
  end
12
14
 
@@ -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
@@ -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
 
@@ -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 < Spicerack::RootObject
13
+ class FlowBase < RootObject
14
14
  include Conjunction::Junction
15
15
  suffixed_with "Flow"
16
16
 
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Flow
4
+ module Malfunction
5
+ class Base < ::Malfunction::MalfunctionBase
6
+ prefixed_with "Flow::Malfunction::"
7
+ suffixed_with nil
8
+ end
9
+ end
10
+ end
@@ -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: :state) if delegate_method_names.any?
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 during execution, but a handler can rescue, it causes a failure instead.
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
@@ -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 < Spicerack::RootObject
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
- expect(object.state.public_send(key)).to match value
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
 
@@ -5,7 +5,7 @@ require_relative "state/output"
5
5
 
6
6
  # A **State** is an aggregation of input and derived data.
7
7
  module Flow
8
- class StateBase < Spicerack::InputModel
8
+ class StateBase < InputModel
9
9
  include Conjunction::Junction
10
10
  suffixed_with "State"
11
11
 
@@ -4,27 +4,27 @@
4
4
  module Flow
5
5
  class StateProxy
6
6
  def initialize(state)
7
- @state = state
7
+ @_state = state
8
8
  end
9
9
 
10
10
  # @deprecated
11
11
  def method_missing(method_name, *arguments, &block)
12
- return super unless state.respond_to?(method_name)
12
+ return super unless _state.respond_to?(method_name)
13
13
 
14
14
  ActiveSupport::Deprecation.warn(
15
- "Direct state access of `#{method_name}' on #{state.inspect} will be removed in a future version of flow. "\
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
- state.public_send(method_name, *arguments, &block)
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
- state.respond_to?(method_name) || super
23
+ _state.respond_to?(method_name) || super
24
24
  end
25
25
 
26
26
  private
27
27
 
28
- attr_reader :state
28
+ attr_reader :_state
29
29
  end
30
30
  end
data/lib/flow/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Flow
4
- VERSION = "0.10.6"
4
+ VERSION = "0.10.9"
5
5
  end
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.6
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: 2020-01-09 00:00:00.000000000 Z
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: activerecord
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: activesupport
46
+ name: spicerack
47
47
  requirement: !ruby/object:Gem::Requirement
48
48
  requirements:
49
49
  - - ">="
50
50
  - !ruby/object:Gem::Version
51
- version: 5.2.1
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: 5.2.1
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: spicery
126
+ name: malfunction
61
127
  requirement: !ruby/object:Gem::Requirement
62
128
  requirements:
63
129
  - - ">="
64
130
  - !ruby/object:Gem::Version
65
- version: 0.20.4
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.20.4
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: '10.0'
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: '10.0'
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.20.4
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.20.4
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.20.4
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.20.4
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
- rubyforge_project:
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.