flow 0.10.0 → 0.10.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8e881d33993ef70f023c82f8c595d77780487a67625c050849e1688c02dc4ccd
4
- data.tar.gz: 7624fed517717e114ba494ce5ae93f252329ee704730a7579f02d4e20f7a53c7
3
+ metadata.gz: 6bb7054475f94b6d73503adf9168e31222098af20a36c048cdf72b68b3e0a7a5
4
+ data.tar.gz: 3a6feb462916f4d24dd180d88e63527ad1e18a4d99e8cbb5ecae664d919e744a
5
5
  SHA512:
6
- metadata.gz: 6a07515e6214de6df0e568d18d3a04692d59d99aa50d8b3fb2ed5f89d394ed4ee0d78dcff05aabd86780df8484f240ca3cb2213bb37ad4e4bc5f8a17ec48454e
7
- data.tar.gz: 2d09e0ca74029c270ae49a73287eef064669a5924cfec2fcd8d72ccf959edc6fa49f9625a4aad393213f24a39d498f990ddb3b451d6e08e84e67699c9c1afe9e
6
+ metadata.gz: 467c98e3ab094d2af99c8c27b72cd493c4efb70bec3980c8dbe6c37d3f6101b829ded1fd80445adf4cbd83195d6143c97c4be3ddf1d1f9c87a19ab875aea07da
7
+ data.tar.gz: 2bcb846816f4f3ad8599dd14970e7ffe6e5d8d0bae9b171ca6b763a6940be1105331bab14e9391c2e2d2dd5b2468cb15d15a1797351259f06af57fc09e3fa133
data/README.md CHANGED
@@ -131,6 +131,14 @@ class ExampleFlow < ApplicationState
131
131
  end
132
132
  ```
133
133
 
134
+ If you _already have_ an instance of a state class that you want to execute a Flow on, you can simply pass it directly to trigger:
135
+
136
+ ```ruby
137
+ state_instance = ExampleState.new(...)
138
+
139
+ CalculateTimetablesFlow.trigger(state_instance)
140
+ ```
141
+
134
142
  ### Operations
135
143
 
136
144
  An **Operation** is a service object which is executed with a **State**.
@@ -299,7 +307,7 @@ If the default value is static, it can be specified in the class definition.
299
307
 
300
308
  If the default value is dynamic, you may provide a block to compute the default value.
301
309
 
302
- ⚠️‍ **Heads Up**: The default value blocks **DO NOT** provide access to the state or it's other variables!
310
+ ⚠️‍ **Heads Up**: The default value blocks **DO NOT** provide access to the state or its other variables!
303
311
 
304
312
  ```ruby
305
313
  class ExampleFlow < ApplicationFlow; end
@@ -4,9 +4,7 @@ require "active_model"
4
4
  require "active_record"
5
5
  require "active_support"
6
6
 
7
- require "instructor"
8
- require "short_circu_it"
9
- require "technologic"
7
+ require "spicerack"
10
8
 
11
9
  require "flow/version"
12
10
 
@@ -18,8 +18,10 @@ module Flow
18
18
  attr_reader :state
19
19
  end
20
20
 
21
- def initialize(**input)
22
- run_callbacks(:initialize) { @state = state_class.new(**input) }
21
+ def initialize(state_instance = nil, **options)
22
+ run_callbacks(:initialize) do
23
+ @state = state_instance || state_class.new(**options)
24
+ end
23
25
  end
24
26
  end
25
27
  end
@@ -1,7 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "instructor/spec_helper"
3
+ require "spicerack/spec_helper"
4
4
 
5
- require_relative "custom_matchers"
6
- require_relative "shoulda_matcher_helper"
7
- require_relative "rspec_configuration"
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"
@@ -29,26 +29,28 @@
29
29
  # it { is_expected.to have_on_state foo: "some data", bar: "some other data" }
30
30
  # end
31
31
 
32
- module CustomMatchers
33
- def have_on_state(expectations)
34
- HaveOnState.new(expectations)
35
- end
32
+ module Flow
33
+ module CustomMatchers
34
+ def have_on_state(expectations)
35
+ HaveOnState.new(expectations)
36
+ end
36
37
 
37
- class HaveOnState
38
- include RSpec::Matchers
38
+ class HaveOnState
39
+ include RSpec::Matchers
39
40
 
40
- def initialize(state_expectations)
41
- @state_expectations = state_expectations
42
- end
41
+ def initialize(state_expectations)
42
+ @state_expectations = state_expectations
43
+ end
43
44
 
44
- def matches?(object)
45
- @state_expectations.all? do |key, value|
46
- expect(object.state.public_send(key)).to match value
45
+ def matches?(object)
46
+ @state_expectations.all? do |key, value|
47
+ expect(object.state.public_send(key)).to match value
48
+ end
47
49
  end
48
- end
49
50
 
50
- def description
51
- "have the expected data on state"
51
+ def description
52
+ "have the expected data on state"
53
+ end
52
54
  end
53
55
  end
54
56
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  RSpec.configure do |config|
4
- config.include CustomMatchers
4
+ config.include Flow::CustomMatchers
5
5
  end
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "shared_contexts/with_failing_operation"
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Stubs a given flow to always fail when triggered.
4
+ #
5
+ # Usage:
6
+ # describe SomeFlow do
7
+ # let(:flow) { described_class.new }
8
+ # let(:failing_flow_class) { described_class }
9
+ #
10
+ # include_context "with failing operation"
11
+ #
12
+ # before { flow.trigger }
13
+ #
14
+ # it "is failed" do
15
+ # expect(flow).to be_failed
16
+ # expect(flow.failed_operation.operation_failure.problem).to eq failing_problem
17
+ # end
18
+ # end
19
+ #
20
+ # Requires let variables to be defined in the inclusion context:
21
+ # * failing_flow_class
22
+ #
23
+ # Defines the following variable:
24
+ # * failure_problem
25
+ RSpec.shared_context "with failing operation" do
26
+ let(:failure_problem) { Faker::Lorem.words.join("-").parameterize.underscore }
27
+ let(:failing_operation) do
28
+ Class.new(Flow::OperationBase).tap do |klass|
29
+ klass.instance_exec(self) do |spec_context|
30
+ failure spec_context.failure_problem
31
+
32
+ define_method :behavior do
33
+ instance_eval("#{spec_context.failure_problem}_failure!")
34
+ end
35
+ end
36
+ end
37
+ end
38
+
39
+ before do
40
+ allow(failing_flow_class).to receive(:_operations).and_return([ failing_operation ])
41
+ stub_const("FailingOperation", failing_operation)
42
+ end
43
+ end
@@ -7,7 +7,7 @@ require_relative "state/output"
7
7
 
8
8
  # A **State** is an aggregation of input and derived data.
9
9
  module Flow
10
- class StateBase < Instructor::Base
10
+ class StateBase < Spicerack::InputModel
11
11
  include Flow::State::Status
12
12
  include Flow::State::Output
13
13
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Flow
4
- VERSION = "0.10.0"
4
+ VERSION = "0.10.1"
5
5
  end
metadata CHANGED
@@ -1,17 +1,18 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flow
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.0
4
+ version: 0.10.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric Garside
8
8
  - Allen Rettberg
9
9
  - Jordan Minneti
10
10
  - Vinod Lala
11
+ - Andrew Cross
11
12
  autorequire:
12
13
  bindir: bin
13
14
  cert_chain: []
14
- date: 2019-05-13 00:00:00.000000000 Z
15
+ date: 2019-06-14 00:00:00.000000000 Z
15
16
  dependencies:
16
17
  - !ruby/object:Gem::Dependency
17
18
  name: activemodel
@@ -59,16 +60,22 @@ dependencies:
59
60
  name: spicerack
60
61
  requirement: !ruby/object:Gem::Requirement
61
62
  requirements:
62
- - - "~>"
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ version: 0.13.3
66
+ - - "<"
63
67
  - !ruby/object:Gem::Version
64
- version: 0.8.3
68
+ version: '1.0'
65
69
  type: :runtime
66
70
  prerelease: false
67
71
  version_requirements: !ruby/object:Gem::Requirement
68
72
  requirements:
69
- - - "~>"
73
+ - - ">="
70
74
  - !ruby/object:Gem::Version
71
- version: 0.8.3
75
+ version: 0.13.3
76
+ - - "<"
77
+ - !ruby/object:Gem::Version
78
+ version: '1.0'
72
79
  - !ruby/object:Gem::Dependency
73
80
  name: bundler
74
81
  requirement: !ruby/object:Gem::Requirement
@@ -171,30 +178,42 @@ dependencies:
171
178
  name: rspice
172
179
  requirement: !ruby/object:Gem::Requirement
173
180
  requirements:
174
- - - "~>"
181
+ - - ">="
182
+ - !ruby/object:Gem::Version
183
+ version: 0.13.3
184
+ - - "<"
175
185
  - !ruby/object:Gem::Version
176
- version: 0.8.3
186
+ version: '1.0'
177
187
  type: :development
178
188
  prerelease: false
179
189
  version_requirements: !ruby/object:Gem::Requirement
180
190
  requirements:
181
- - - "~>"
191
+ - - ">="
192
+ - !ruby/object:Gem::Version
193
+ version: 0.13.3
194
+ - - "<"
182
195
  - !ruby/object:Gem::Version
183
- version: 0.8.3
196
+ version: '1.0'
184
197
  - !ruby/object:Gem::Dependency
185
198
  name: spicerack-styleguide
186
199
  requirement: !ruby/object:Gem::Requirement
187
200
  requirements:
188
- - - "~>"
201
+ - - ">="
189
202
  - !ruby/object:Gem::Version
190
- version: 0.8.3
203
+ version: 0.13.3
204
+ - - "<"
205
+ - !ruby/object:Gem::Version
206
+ version: '1.0'
191
207
  type: :development
192
208
  prerelease: false
193
209
  version_requirements: !ruby/object:Gem::Requirement
194
210
  requirements:
195
- - - "~>"
211
+ - - ">="
212
+ - !ruby/object:Gem::Version
213
+ version: 0.13.3
214
+ - - "<"
196
215
  - !ruby/object:Gem::Version
197
- version: 0.8.3
216
+ version: '1.0'
198
217
  - !ruby/object:Gem::Dependency
199
218
  name: shoulda-matchers
200
219
  requirement: !ruby/object:Gem::Requirement
@@ -221,13 +240,6 @@ files:
221
240
  - README.md
222
241
  - lib/flow.rb
223
242
  - lib/flow/concerns/transaction_wrapper.rb
224
- - lib/flow/custom_matchers.rb
225
- - lib/flow/custom_matchers/define_failure.rb
226
- - lib/flow/custom_matchers/define_output.rb
227
- - lib/flow/custom_matchers/handle_error.rb
228
- - lib/flow/custom_matchers/have_on_state.rb
229
- - lib/flow/custom_matchers/use_operations.rb
230
- - lib/flow/custom_matchers/wrap_in_transaction.rb
231
243
  - lib/flow/flow/callbacks.rb
232
244
  - lib/flow/flow/core.rb
233
245
  - lib/flow/flow/errors/state_invalid.rb
@@ -248,9 +260,18 @@ files:
248
260
  - lib/flow/operation/status.rb
249
261
  - lib/flow/operation/transactions.rb
250
262
  - lib/flow/operation_base.rb
251
- - lib/flow/rspec_configuration.rb
252
- - lib/flow/shoulda_matcher_helper.rb
253
263
  - 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
254
275
  - lib/flow/state/errors/not_validated.rb
255
276
  - lib/flow/state/output.rb
256
277
  - lib/flow/state/status.rb