flow 0.10.5 → 0.10.8

Sign up to get free protection for your applications and to get access to all the features.
data/lib/flow.rb CHANGED
@@ -5,25 +5,21 @@ require "active_record"
5
5
  require "active_support"
6
6
 
7
7
  require "spicerack"
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"
@@ -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
@@ -8,7 +8,7 @@ module Flow
8
8
 
9
9
  class_methods do
10
10
  def state_class
11
- "#{name.chomp("Flow")}State".constantize
11
+ conjugate(StateBase)
12
12
  end
13
13
  end
14
14
 
@@ -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,10 @@ 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
+ include Conjunction::Junction
15
+ suffixed_with "Flow"
16
+
14
17
  include TransactionWrapper
15
18
  include Flow::Callbacks
16
19
  include Flow::Core
@@ -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,10 @@ 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
+ include Conjunction::Junction
10
+ suffixed_with "State"
11
+
9
12
  include State::Status
10
13
  include State::Output
11
14
  end
@@ -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.5"
4
+ VERSION = "0.10.8"
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.5
4
+ version: 0.10.8
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-08 00:00:00.000000000 Z
15
+ date: 2021-06-03 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: activemodel
@@ -62,7 +62,7 @@ dependencies:
62
62
  requirements:
63
63
  - - ">="
64
64
  - !ruby/object:Gem::Version
65
- version: 0.13.3
65
+ version: 0.2.0
66
66
  - - "<"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '1.0'
@@ -72,80 +72,112 @@ dependencies:
72
72
  requirements:
73
73
  - - ">="
74
74
  - !ruby/object:Gem::Version
75
- version: 0.13.3
75
+ version: 0.2.0
76
76
  - - "<"
77
77
  - !ruby/object:Gem::Version
78
78
  version: '1.0'
79
79
  - !ruby/object:Gem::Dependency
80
- name: bundler
80
+ name: short_circu_it
81
81
  requirement: !ruby/object:Gem::Requirement
82
82
  requirements:
83
- - - "~>"
83
+ - - ">="
84
84
  - !ruby/object:Gem::Version
85
- version: 2.0.1
86
- type: :development
85
+ version: 0.2.0
86
+ - - "<"
87
+ - !ruby/object:Gem::Version
88
+ version: '1.0'
89
+ type: :runtime
87
90
  prerelease: false
88
91
  version_requirements: !ruby/object:Gem::Requirement
89
92
  requirements:
90
- - - "~>"
93
+ - - ">="
91
94
  - !ruby/object:Gem::Version
92
- version: 2.0.1
95
+ version: 0.2.0
96
+ - - "<"
97
+ - !ruby/object:Gem::Version
98
+ version: '1.0'
93
99
  - !ruby/object:Gem::Dependency
94
- name: rake
100
+ name: technologic
95
101
  requirement: !ruby/object:Gem::Requirement
96
102
  requirements:
97
- - - "~>"
103
+ - - ">="
98
104
  - !ruby/object:Gem::Version
99
- version: '10.0'
100
- type: :development
105
+ version: 0.2.0
106
+ - - "<"
107
+ - !ruby/object:Gem::Version
108
+ version: '1.0'
109
+ type: :runtime
101
110
  prerelease: false
102
111
  version_requirements: !ruby/object:Gem::Requirement
103
112
  requirements:
104
- - - "~>"
113
+ - - ">="
105
114
  - !ruby/object:Gem::Version
106
- version: '10.0'
115
+ version: 0.2.0
116
+ - - "<"
117
+ - !ruby/object:Gem::Version
118
+ version: '1.0'
107
119
  - !ruby/object:Gem::Dependency
108
- name: rspec
120
+ name: malfunction
109
121
  requirement: !ruby/object:Gem::Requirement
110
122
  requirements:
111
- - - "~>"
123
+ - - ">="
124
+ - !ruby/object:Gem::Version
125
+ version: 0.2.0
126
+ - - "<"
127
+ - !ruby/object:Gem::Version
128
+ version: '1.0'
129
+ type: :runtime
130
+ prerelease: false
131
+ version_requirements: !ruby/object:Gem::Requirement
132
+ requirements:
133
+ - - ">="
112
134
  - !ruby/object:Gem::Version
113
- version: '3.0'
135
+ version: 0.2.0
136
+ - - "<"
137
+ - !ruby/object:Gem::Version
138
+ version: '1.0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: bundler
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: 2.0.1
114
146
  type: :development
115
147
  prerelease: false
116
148
  version_requirements: !ruby/object:Gem::Requirement
117
149
  requirements:
118
- - - "~>"
150
+ - - ">="
119
151
  - !ruby/object:Gem::Version
120
- version: '3.0'
152
+ version: 2.0.1
121
153
  - !ruby/object:Gem::Dependency
122
- name: simplecov
154
+ name: rake
123
155
  requirement: !ruby/object:Gem::Requirement
124
156
  requirements:
125
157
  - - "~>"
126
158
  - !ruby/object:Gem::Version
127
- version: '0.16'
159
+ version: '13.0'
128
160
  type: :development
129
161
  prerelease: false
130
162
  version_requirements: !ruby/object:Gem::Requirement
131
163
  requirements:
132
164
  - - "~>"
133
165
  - !ruby/object:Gem::Version
134
- version: '0.16'
166
+ version: '13.0'
135
167
  - !ruby/object:Gem::Dependency
136
- name: faker
168
+ name: simplecov
137
169
  requirement: !ruby/object:Gem::Requirement
138
170
  requirements:
139
171
  - - "~>"
140
172
  - !ruby/object:Gem::Version
141
- version: '1.8'
173
+ version: '0.16'
142
174
  type: :development
143
175
  prerelease: false
144
176
  version_requirements: !ruby/object:Gem::Requirement
145
177
  requirements:
146
178
  - - "~>"
147
179
  - !ruby/object:Gem::Version
148
- version: '1.8'
180
+ version: '0.16'
149
181
  - !ruby/object:Gem::Dependency
150
182
  name: pry-byebug
151
183
  requirement: !ruby/object:Gem::Requirement
@@ -188,13 +220,27 @@ dependencies:
188
220
  - - "~>"
189
221
  - !ruby/object:Gem::Version
190
222
  version: 3.1.13
223
+ - !ruby/object:Gem::Dependency
224
+ name: shoulda-matchers
225
+ requirement: !ruby/object:Gem::Requirement
226
+ requirements:
227
+ - - '='
228
+ - !ruby/object:Gem::Version
229
+ version: 4.0.1
230
+ type: :development
231
+ prerelease: false
232
+ version_requirements: !ruby/object:Gem::Requirement
233
+ requirements:
234
+ - - '='
235
+ - !ruby/object:Gem::Version
236
+ version: 4.0.1
191
237
  - !ruby/object:Gem::Dependency
192
238
  name: rspice
193
239
  requirement: !ruby/object:Gem::Requirement
194
240
  requirements:
195
241
  - - ">="
196
242
  - !ruby/object:Gem::Version
197
- version: 0.13.3
243
+ version: 0.25.7
198
244
  - - "<"
199
245
  - !ruby/object:Gem::Version
200
246
  version: '1.0'
@@ -204,7 +250,7 @@ dependencies:
204
250
  requirements:
205
251
  - - ">="
206
252
  - !ruby/object:Gem::Version
207
- version: 0.13.3
253
+ version: 0.25.7
208
254
  - - "<"
209
255
  - !ruby/object:Gem::Version
210
256
  version: '1.0'
@@ -214,7 +260,7 @@ dependencies:
214
260
  requirements:
215
261
  - - ">="
216
262
  - !ruby/object:Gem::Version
217
- version: 0.13.3
263
+ version: 0.21.0
218
264
  - - "<"
219
265
  - !ruby/object:Gem::Version
220
266
  version: '1.0'
@@ -224,24 +270,10 @@ dependencies:
224
270
  requirements:
225
271
  - - ">="
226
272
  - !ruby/object:Gem::Version
227
- version: 0.13.3
273
+ version: 0.21.0
228
274
  - - "<"
229
275
  - !ruby/object:Gem::Version
230
276
  version: '1.0'
231
- - !ruby/object:Gem::Dependency
232
- name: shoulda-matchers
233
- requirement: !ruby/object:Gem::Requirement
234
- requirements:
235
- - - '='
236
- - !ruby/object:Gem::Version
237
- version: 4.0.1
238
- type: :development
239
- prerelease: false
240
- version_requirements: !ruby/object:Gem::Requirement
241
- requirements:
242
- - - '='
243
- - !ruby/object:Gem::Version
244
- version: 4.0.1
245
277
  description: Tired of kitchen sink services, god-objects, and fat-everything? So were
246
278
  we. Get in the flow.
247
279
  email:
@@ -254,6 +286,7 @@ files:
254
286
  - README.md
255
287
  - lib/flow.rb
256
288
  - lib/flow/concerns/transaction_wrapper.rb
289
+ - lib/flow/errors.rb
257
290
  - lib/flow/flow/callbacks.rb
258
291
  - lib/flow/flow/core.rb
259
292
  - lib/flow/flow/flux.rb
@@ -262,6 +295,7 @@ files:
262
295
  - lib/flow/flow/transactions.rb
263
296
  - lib/flow/flow/trigger.rb
264
297
  - lib/flow/flow_base.rb
298
+ - lib/flow/malfunction/base.rb
265
299
  - lib/flow/operation/accessors.rb
266
300
  - lib/flow/operation/callbacks.rb
267
301
  - lib/flow/operation/core.rb
@@ -348,8 +382,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
348
382
  - !ruby/object:Gem::Version
349
383
  version: '0'
350
384
  requirements: []
351
- rubyforge_project:
352
- rubygems_version: 2.7.6
385
+ rubygems_version: 3.2.17
353
386
  signing_key:
354
387
  specification_version: 4
355
388
  summary: Write modular and reusable business logic that's understandable and maintainable.