flow 0.10.2 → 0.10.7.1.pre1

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.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +107 -1116
  3. data/lib/flow.rb +17 -2
  4. data/lib/flow/flow/callbacks.rb +7 -5
  5. data/lib/flow/flow/core.rb +16 -14
  6. data/lib/flow/flow/flux.rb +36 -32
  7. data/lib/flow/flow/operations.rb +16 -14
  8. data/lib/flow/flow/status.rb +15 -13
  9. data/lib/flow/flow/transactions.rb +7 -5
  10. data/lib/flow/flow/trigger.rb +26 -24
  11. data/lib/flow/flow_base.rb +5 -6
  12. data/lib/flow/malfunction/base.rb +10 -0
  13. data/lib/flow/operation/core.rb +12 -1
  14. data/lib/flow/operation/error_handler.rb +1 -1
  15. data/lib/flow/operation/execute.rb +1 -1
  16. data/lib/flow/operation_base.rb +10 -15
  17. data/lib/flow/{spec_helper/rspec_configuration.rb → rspec/configuration.rb} +0 -0
  18. data/lib/flow/{spec_helper → rspec}/custom_matchers.rb +3 -0
  19. data/lib/flow/rspec/custom_matchers/access_state.rb +27 -0
  20. data/lib/flow/{spec_helper → rspec}/custom_matchers/define_failure.rb +0 -0
  21. data/lib/flow/{spec_helper → rspec}/custom_matchers/define_output.rb +0 -0
  22. data/lib/flow/{spec_helper → rspec}/custom_matchers/handle_error.rb +0 -0
  23. data/lib/flow/{spec_helper → rspec}/custom_matchers/have_on_state.rb +6 -1
  24. data/lib/flow/rspec/custom_matchers/read_state.rb +23 -0
  25. data/lib/flow/{spec_helper → rspec}/custom_matchers/use_operations.rb +0 -0
  26. data/lib/flow/{spec_helper → rspec}/custom_matchers/wrap_in_transaction.rb +0 -0
  27. data/lib/flow/rspec/custom_matchers/write_state.rb +23 -0
  28. data/lib/flow/{spec_helper → rspec}/shared_contexts.rb +0 -0
  29. data/lib/flow/{spec_helper → rspec}/shared_contexts/with_failing_operation.rb +0 -0
  30. data/lib/flow/{spec_helper → rspec}/shoulda_matcher_helper.rb +0 -0
  31. data/lib/flow/spec_helper.rb +4 -4
  32. data/lib/flow/state/output.rb +1 -1
  33. data/lib/flow/state_base.rb +5 -4
  34. data/lib/flow/state_proxy.rb +30 -0
  35. data/lib/flow/version.rb +1 -1
  36. data/lib/generators/flow/operation/templates/operation.rb.erb +4 -0
  37. data/lib/generators/rspec/application_operation/templates/application_operation_spec.rb +9 -5
  38. data/lib/generators/rspec/operation/templates/operation_spec.rb.erb +4 -0
  39. metadata +73 -66
  40. data/lib/flow/flow/errors/state_invalid.rb +0 -7
  41. data/lib/flow/operation/errors/already_executed.rb +0 -9
  42. data/lib/flow/operation/errors/already_rewound.rb +0 -9
  43. data/lib/flow/state/errors/not_validated.rb +0 -9
@@ -6,3 +6,6 @@ require_relative "custom_matchers/handle_error"
6
6
  require_relative "custom_matchers/use_operations"
7
7
  require_relative "custom_matchers/wrap_in_transaction"
8
8
  require_relative "custom_matchers/have_on_state"
9
+ require_relative "custom_matchers/read_state"
10
+ require_relative "custom_matchers/write_state"
11
+ require_relative "custom_matchers/access_state"
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ # RSpec matcher that tests usage of `ApplicationOperation.state_accessor` (or use of both `state_(reader|writer)`)
4
+ #
5
+ # class SomeTask < ApplicationOperation
6
+ # state_accessor :foo
7
+ # state_accessor :bar
8
+ #
9
+ # state_reader :baz
10
+ # state_writer :baz
11
+ # end
12
+ #
13
+ # RSpec.describe SomeTask, type: :operation do
14
+ # subject { described_class.new(state) }
15
+ #
16
+ # let(:state) { Class.new(ApplicationState).new }
17
+ #
18
+ # it { is_expected.to access_state :foo }
19
+ # it { is_expected.to access_state :bar }
20
+ # it { is_expected.to access_state :baz }
21
+ # end
22
+
23
+ RSpec::Matchers.define :access_state do |field|
24
+ match { |operation| expect(operation._state_accessors).to include field }
25
+ description { "access state" }
26
+ failure_message { "expected #{described_class} to access state #{field}" }
27
+ end
@@ -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)
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
 
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ # RSpec matcher that tests usage of `ApplicationOperation.state_reader`
4
+ #
5
+ # class SomeTask < ApplicationOperation
6
+ # state_reader :foo
7
+ # state_reader :bar
8
+ # end
9
+ #
10
+ # RSpec.describe SomeTask, type: :operation do
11
+ # subject { described_class.new(state) }
12
+ #
13
+ # let(:state) { Class.new(ApplicationState).new }
14
+ #
15
+ # it { is_expected.to read_state :foo }
16
+ # it { is_expected.to read_state :bar }
17
+ # end
18
+
19
+ RSpec::Matchers.define :read_state do |field|
20
+ match { |operation| expect(operation._state_readers).to include field }
21
+ description { "read state" }
22
+ failure_message { "expected #{described_class} to read state #{field}" }
23
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ # RSpec matcher that tests usage of `ApplicationOperation.state_writer`
4
+ #
5
+ # class SomeTask < ApplicationOperation
6
+ # state_writer :foo
7
+ # state_writer :bar
8
+ # end
9
+ #
10
+ # RSpec.describe SomeTask, type: :operation do
11
+ # subject { described_class.new(state) }
12
+ #
13
+ # let(:state) { Class.new(ApplicationState).new }
14
+ #
15
+ # it { is_expected.to write_state :foo }
16
+ # it { is_expected.to write_state :bar }
17
+ # end
18
+
19
+ RSpec::Matchers.define :write_state do |field|
20
+ match { |operation| expect(operation._state_writers).to include field }
21
+ description { "write state" }
22
+ failure_message { "expected #{described_class} to write state #{field}" }
23
+ end
File without changes
@@ -2,7 +2,7 @@
2
2
 
3
3
  require "spicerack/spec_helper"
4
4
 
5
- require_relative "spec_helper/custom_matchers"
6
- require_relative "spec_helper/shared_contexts"
7
- require_relative "spec_helper/shoulda_matcher_helper"
8
- require_relative "spec_helper/rspec_configuration"
5
+ require_relative "rspec/custom_matchers"
6
+ require_relative "rspec/shared_contexts"
7
+ require_relative "rspec/shoulda_matcher_helper"
8
+ require_relative "rspec/configuration"
@@ -38,7 +38,7 @@ module Flow
38
38
 
39
39
  def ensure_validation_before(method)
40
40
  around_method method do |*arguments|
41
- raise Flow::State::Errors::NotValidated unless validated?
41
+ raise NotValidatedError unless validated?
42
42
 
43
43
  super(*arguments)
44
44
  end
@@ -1,14 +1,15 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "state/errors/not_validated"
4
-
5
3
  require_relative "state/status"
6
4
  require_relative "state/output"
7
5
 
8
6
  # A **State** is an aggregation of input and derived data.
9
7
  module Flow
10
8
  class StateBase < Spicerack::InputModel
11
- include Flow::State::Status
12
- include Flow::State::Output
9
+ include Conjunction::Junction
10
+ suffixed_with "State"
11
+
12
+ include State::Status
13
+ include State::Output
13
14
  end
14
15
  end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ # A **StateProxy** adapts a **State** to an **Operation** through an Operation's `state_*` accessors.
4
+ module Flow
5
+ class StateProxy
6
+ def initialize(state)
7
+ @_state = state
8
+ end
9
+
10
+ # @deprecated
11
+ def method_missing(method_name, *arguments, &block)
12
+ return super unless _state.respond_to?(method_name)
13
+
14
+ ActiveSupport::Deprecation.warn(
15
+ "Direct state access of `#{method_name}' on #{_state.inspect} will be removed in a future version of flow. "\
16
+ "Use a state accessor instead - for more information see github/freshly/flow/deprecation_notice"
17
+ )
18
+ _state.public_send(method_name, *arguments, &block)
19
+ end
20
+
21
+ # @deprecated
22
+ def respond_to_missing?(method_name, include_private = false)
23
+ _state.respond_to?(method_name) || super
24
+ end
25
+
26
+ private
27
+
28
+ attr_reader :_state
29
+ end
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.2"
4
+ VERSION = "0.10.7.1.pre1"
5
5
  end
@@ -1,6 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class <%= class_name %> < ApplicationOperation
4
+ # state_accessor :foo
5
+ # state_reader :bar
6
+ # state_writer :baz
7
+
4
8
  def behavior
5
9
  # Define what this operation does here
6
10
  end
@@ -3,15 +3,19 @@
3
3
  require "rails_helper"
4
4
 
5
5
  RSpec.describe ApplicationOperation, type: :operation do
6
- subject(:operation) { described_class.new(state) }
7
-
8
- let(:state) { double }
6
+ subject { described_class }
9
7
 
10
8
  it { is_expected.to inherit_from Flow::OperationBase }
11
9
 
12
10
  describe "#execute" do
13
11
  subject(:execute) { operation.execute }
14
-
15
- it "has some behavior"
12
+
13
+ context "when unsuccessful" do
14
+ pending "describe the effects of an unsuccessful `Operation#execute` (or delete) #{__FILE__}"
15
+ end
16
+
17
+ context "when successful" do
18
+ pending "describe the effects of a successful `Operation#execute` (or delete) #{__FILE__}"
19
+ end
16
20
  end
17
21
  end
@@ -19,6 +19,10 @@ RSpec.describe <%= class_name %>, type: :operation do
19
19
 
20
20
  it { is_expected.to inherit_from ApplicationOperation }
21
21
 
22
+ # it { is_expected.to access_state :foo }
23
+ # it { is_expected.to read_state :bar }
24
+ # it { is_expected.to write_state :baz }
25
+
22
26
  describe "#execute" do
23
27
  subject(:execute) { operation.execute }
24
28
 
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.2
4
+ version: 0.10.7.1.pre1
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: 2019-09-19 00:00:00.000000000 Z
15
+ date: 2021-04-09 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: activemodel
@@ -57,12 +57,12 @@ dependencies:
57
57
  - !ruby/object:Gem::Version
58
58
  version: 5.2.1
59
59
  - !ruby/object:Gem::Dependency
60
- name: spicerack
60
+ name: spicery
61
61
  requirement: !ruby/object:Gem::Requirement
62
62
  requirements:
63
63
  - - ">="
64
64
  - !ruby/object:Gem::Version
65
- version: 0.13.3
65
+ version: 0.21.0
66
66
  - - "<"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '1.0'
@@ -72,7 +72,27 @@ dependencies:
72
72
  requirements:
73
73
  - - ">="
74
74
  - !ruby/object:Gem::Version
75
- version: 0.13.3
75
+ version: 0.21.0
76
+ - - "<"
77
+ - !ruby/object:Gem::Version
78
+ version: '1.0'
79
+ - !ruby/object:Gem::Dependency
80
+ name: malfunction
81
+ requirement: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: 0.2.0
86
+ - - "<"
87
+ - !ruby/object:Gem::Version
88
+ version: '1.0'
89
+ type: :runtime
90
+ prerelease: false
91
+ version_requirements: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: 0.2.0
76
96
  - - "<"
77
97
  - !ruby/object:Gem::Version
78
98
  version: '1.0'
@@ -80,14 +100,14 @@ dependencies:
80
100
  name: bundler
81
101
  requirement: !ruby/object:Gem::Requirement
82
102
  requirements:
83
- - - "~>"
103
+ - - ">="
84
104
  - !ruby/object:Gem::Version
85
105
  version: 2.0.1
86
106
  type: :development
87
107
  prerelease: false
88
108
  version_requirements: !ruby/object:Gem::Requirement
89
109
  requirements:
90
- - - "~>"
110
+ - - ">="
91
111
  - !ruby/object:Gem::Version
92
112
  version: 2.0.1
93
113
  - !ruby/object:Gem::Dependency
@@ -96,91 +116,91 @@ dependencies:
96
116
  requirements:
97
117
  - - "~>"
98
118
  - !ruby/object:Gem::Version
99
- version: '10.0'
119
+ version: '13.0'
100
120
  type: :development
101
121
  prerelease: false
102
122
  version_requirements: !ruby/object:Gem::Requirement
103
123
  requirements:
104
124
  - - "~>"
105
125
  - !ruby/object:Gem::Version
106
- version: '10.0'
126
+ version: '13.0'
107
127
  - !ruby/object:Gem::Dependency
108
- name: rspec
128
+ name: simplecov
109
129
  requirement: !ruby/object:Gem::Requirement
110
130
  requirements:
111
131
  - - "~>"
112
132
  - !ruby/object:Gem::Version
113
- version: '3.0'
133
+ version: '0.16'
114
134
  type: :development
115
135
  prerelease: false
116
136
  version_requirements: !ruby/object:Gem::Requirement
117
137
  requirements:
118
138
  - - "~>"
119
139
  - !ruby/object:Gem::Version
120
- version: '3.0'
140
+ version: '0.16'
121
141
  - !ruby/object:Gem::Dependency
122
- name: simplecov
142
+ name: pry-byebug
123
143
  requirement: !ruby/object:Gem::Requirement
124
144
  requirements:
125
- - - "~>"
145
+ - - ">="
126
146
  - !ruby/object:Gem::Version
127
- version: '0.16'
147
+ version: 3.7.0
128
148
  type: :development
129
149
  prerelease: false
130
150
  version_requirements: !ruby/object:Gem::Requirement
131
151
  requirements:
132
- - - "~>"
152
+ - - ">="
133
153
  - !ruby/object:Gem::Version
134
- version: '0.16'
154
+ version: 3.7.0
135
155
  - !ruby/object:Gem::Dependency
136
- name: faker
156
+ name: sqlite3
137
157
  requirement: !ruby/object:Gem::Requirement
138
158
  requirements:
139
159
  - - "~>"
140
160
  - !ruby/object:Gem::Version
141
- version: '1.8'
161
+ version: '1.3'
142
162
  type: :development
143
163
  prerelease: false
144
164
  version_requirements: !ruby/object:Gem::Requirement
145
165
  requirements:
146
166
  - - "~>"
147
167
  - !ruby/object:Gem::Version
148
- version: '1.8'
168
+ version: '1.3'
149
169
  - !ruby/object:Gem::Dependency
150
- name: pry-byebug
170
+ name: bcrypt
151
171
  requirement: !ruby/object:Gem::Requirement
152
172
  requirements:
153
- - - ">="
173
+ - - "~>"
154
174
  - !ruby/object:Gem::Version
155
- version: 3.7.0
175
+ version: 3.1.13
156
176
  type: :development
157
177
  prerelease: false
158
178
  version_requirements: !ruby/object:Gem::Requirement
159
179
  requirements:
160
- - - ">="
180
+ - - "~>"
161
181
  - !ruby/object:Gem::Version
162
- version: 3.7.0
182
+ version: 3.1.13
163
183
  - !ruby/object:Gem::Dependency
164
- name: sqlite3
184
+ name: shoulda-matchers
165
185
  requirement: !ruby/object:Gem::Requirement
166
186
  requirements:
167
- - - "~>"
187
+ - - '='
168
188
  - !ruby/object:Gem::Version
169
- version: '1.3'
189
+ version: 4.0.1
170
190
  type: :development
171
191
  prerelease: false
172
192
  version_requirements: !ruby/object:Gem::Requirement
173
193
  requirements:
174
- - - "~>"
194
+ - - '='
175
195
  - !ruby/object:Gem::Version
176
- version: '1.3'
196
+ version: 4.0.1
177
197
  - !ruby/object:Gem::Dependency
178
198
  name: rspice
179
199
  requirement: !ruby/object:Gem::Requirement
180
200
  requirements:
181
201
  - - ">="
182
202
  - !ruby/object:Gem::Version
183
- version: 0.13.3
203
+ version: 0.25.7
184
204
  - - "<"
185
205
  - !ruby/object:Gem::Version
186
206
  version: '1.0'
@@ -190,7 +210,7 @@ dependencies:
190
210
  requirements:
191
211
  - - ">="
192
212
  - !ruby/object:Gem::Version
193
- version: 0.13.3
213
+ version: 0.25.7
194
214
  - - "<"
195
215
  - !ruby/object:Gem::Version
196
216
  version: '1.0'
@@ -200,7 +220,7 @@ dependencies:
200
220
  requirements:
201
221
  - - ">="
202
222
  - !ruby/object:Gem::Version
203
- version: 0.13.3
223
+ version: 0.21.0
204
224
  - - "<"
205
225
  - !ruby/object:Gem::Version
206
226
  version: '1.0'
@@ -210,24 +230,10 @@ dependencies:
210
230
  requirements:
211
231
  - - ">="
212
232
  - !ruby/object:Gem::Version
213
- version: 0.13.3
233
+ version: 0.21.0
214
234
  - - "<"
215
235
  - !ruby/object:Gem::Version
216
236
  version: '1.0'
217
- - !ruby/object:Gem::Dependency
218
- name: shoulda-matchers
219
- requirement: !ruby/object:Gem::Requirement
220
- requirements:
221
- - - '='
222
- - !ruby/object:Gem::Version
223
- version: 4.0.1
224
- type: :development
225
- prerelease: false
226
- version_requirements: !ruby/object:Gem::Requirement
227
- requirements:
228
- - - '='
229
- - !ruby/object:Gem::Version
230
- version: 4.0.1
231
237
  description: Tired of kitchen sink services, god-objects, and fat-everything? So were
232
238
  we. Get in the flow.
233
239
  email:
@@ -242,40 +248,41 @@ files:
242
248
  - lib/flow/concerns/transaction_wrapper.rb
243
249
  - lib/flow/flow/callbacks.rb
244
250
  - lib/flow/flow/core.rb
245
- - lib/flow/flow/errors/state_invalid.rb
246
251
  - lib/flow/flow/flux.rb
247
252
  - lib/flow/flow/operations.rb
248
253
  - lib/flow/flow/status.rb
249
254
  - lib/flow/flow/transactions.rb
250
255
  - lib/flow/flow/trigger.rb
251
256
  - lib/flow/flow_base.rb
257
+ - lib/flow/malfunction/base.rb
252
258
  - lib/flow/operation/accessors.rb
253
259
  - lib/flow/operation/callbacks.rb
254
260
  - lib/flow/operation/core.rb
255
261
  - lib/flow/operation/error_handler.rb
256
- - lib/flow/operation/errors/already_executed.rb
257
- - lib/flow/operation/errors/already_rewound.rb
258
262
  - lib/flow/operation/execute.rb
259
263
  - lib/flow/operation/failures.rb
260
264
  - lib/flow/operation/status.rb
261
265
  - lib/flow/operation/transactions.rb
262
266
  - lib/flow/operation_base.rb
267
+ - lib/flow/rspec/configuration.rb
268
+ - lib/flow/rspec/custom_matchers.rb
269
+ - lib/flow/rspec/custom_matchers/access_state.rb
270
+ - lib/flow/rspec/custom_matchers/define_failure.rb
271
+ - lib/flow/rspec/custom_matchers/define_output.rb
272
+ - lib/flow/rspec/custom_matchers/handle_error.rb
273
+ - lib/flow/rspec/custom_matchers/have_on_state.rb
274
+ - lib/flow/rspec/custom_matchers/read_state.rb
275
+ - lib/flow/rspec/custom_matchers/use_operations.rb
276
+ - lib/flow/rspec/custom_matchers/wrap_in_transaction.rb
277
+ - lib/flow/rspec/custom_matchers/write_state.rb
278
+ - lib/flow/rspec/shared_contexts.rb
279
+ - lib/flow/rspec/shared_contexts/with_failing_operation.rb
280
+ - lib/flow/rspec/shoulda_matcher_helper.rb
263
281
  - lib/flow/spec_helper.rb
264
- - lib/flow/spec_helper/custom_matchers.rb
265
- - lib/flow/spec_helper/custom_matchers/define_failure.rb
266
- - lib/flow/spec_helper/custom_matchers/define_output.rb
267
- - lib/flow/spec_helper/custom_matchers/handle_error.rb
268
- - lib/flow/spec_helper/custom_matchers/have_on_state.rb
269
- - lib/flow/spec_helper/custom_matchers/use_operations.rb
270
- - lib/flow/spec_helper/custom_matchers/wrap_in_transaction.rb
271
- - lib/flow/spec_helper/rspec_configuration.rb
272
- - lib/flow/spec_helper/shared_contexts.rb
273
- - lib/flow/spec_helper/shared_contexts/with_failing_operation.rb
274
- - lib/flow/spec_helper/shoulda_matcher_helper.rb
275
- - lib/flow/state/errors/not_validated.rb
276
282
  - lib/flow/state/output.rb
277
283
  - lib/flow/state/status.rb
278
284
  - lib/flow/state_base.rb
285
+ - lib/flow/state_proxy.rb
279
286
  - lib/flow/version.rb
280
287
  - lib/generators/flow/USAGE
281
288
  - lib/generators/flow/application_flow/USAGE
@@ -330,11 +337,11 @@ required_ruby_version: !ruby/object:Gem::Requirement
330
337
  version: '0'
331
338
  required_rubygems_version: !ruby/object:Gem::Requirement
332
339
  requirements:
333
- - - ">="
340
+ - - ">"
334
341
  - !ruby/object:Gem::Version
335
- version: '0'
342
+ version: 1.3.1
336
343
  requirements: []
337
- rubygems_version: 3.0.3
344
+ rubygems_version: 3.1.4
338
345
  signing_key:
339
346
  specification_version: 4
340
347
  summary: Write modular and reusable business logic that's understandable and maintainable.