business_flow 0.13.0 → 0.14.0
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 +4 -4
- data/Gemfile.lock +1 -1
- data/lib/business_flow/dsl.rb +16 -3
- data/lib/business_flow/step.rb +21 -6
- data/lib/business_flow/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ef0272ca5eb7e69dd6f802b1e684930a2a344021
|
4
|
+
data.tar.gz: 5b02b5d3c8981929d9f7e2675890933562501388
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8238af8e966875e8ffeca8ffa376f73d761158c64ca01b1af8edda23c3f2e6b814f12395d295c99269152de7b478205019ef1bebb4a725113dc4e8324595d7d0
|
7
|
+
data.tar.gz: f8afa54780606ad60029b47eee2c88a832822088ce98922374635ad1e97422341bf8a2d4aa43f8d48bdf05b515f2a06a612c720d83db759b041be2870e7fea38
|
data/Gemfile.lock
CHANGED
data/lib/business_flow/dsl.rb
CHANGED
@@ -15,6 +15,13 @@ module BusinessFlow
|
|
15
15
|
@needs.add_fields(fields)
|
16
16
|
end
|
17
17
|
|
18
|
+
# Allows a field to be retieved form the initialization paramters,
|
19
|
+
# but does not require it to be non-nil
|
20
|
+
def optional(*fields)
|
21
|
+
@optionals ||= FieldList.new([], ParameterField, self)
|
22
|
+
@optionals.add_fields(fields)
|
23
|
+
end
|
24
|
+
|
18
25
|
# Allows a field to be retrieved from the initialiaztion parameters
|
19
26
|
def wants(field, default = proc { nil }, opts = {})
|
20
27
|
internal_name = "wants_#{field}".to_sym
|
@@ -53,7 +60,7 @@ module BusinessFlow
|
|
53
60
|
# :reek:UtilityFunction This is a function on us so that other modules
|
54
61
|
# can change execution behavior.
|
55
62
|
def execute(flow)
|
56
|
-
catch(:halt_step) { flow.call }
|
63
|
+
catch(:halt_step) { flow.call } unless flow.errors?
|
57
64
|
result_from(flow)
|
58
65
|
end
|
59
66
|
|
@@ -304,6 +311,8 @@ module BusinessFlow
|
|
304
311
|
|
305
312
|
# Helper class around memoized fields
|
306
313
|
class MemoizedField
|
314
|
+
attr_reader :field
|
315
|
+
|
307
316
|
def initialize(field, retriever, setter_factory)
|
308
317
|
@field = field
|
309
318
|
@retriever = retriever
|
@@ -319,7 +328,7 @@ module BusinessFlow
|
|
319
328
|
|
320
329
|
private
|
321
330
|
|
322
|
-
attr_reader :
|
331
|
+
attr_reader :retriever, :setter_factory
|
323
332
|
|
324
333
|
def memoized(ivar_name, setter, retriever)
|
325
334
|
<<-MEMOIZED
|
@@ -375,6 +384,7 @@ module BusinessFlow
|
|
375
384
|
|
376
385
|
def add_to(klass)
|
377
386
|
@field.add_to(klass)
|
387
|
+
klass.send(:public, @field.field)
|
378
388
|
end
|
379
389
|
|
380
390
|
private
|
@@ -390,9 +400,12 @@ module BusinessFlow
|
|
390
400
|
@parameters = parameters
|
391
401
|
end
|
392
402
|
|
403
|
+
# :reek:NilCheck
|
393
404
|
def fetch(key)
|
394
405
|
value = inner_fetch(key)
|
395
|
-
|
406
|
+
# We only want to fall back to a default if we were
|
407
|
+
# given nil. Other falsy vlues should be directly used.
|
408
|
+
return yield if value.nil? && block_given?
|
396
409
|
value
|
397
410
|
end
|
398
411
|
|
data/lib/business_flow/step.rb
CHANGED
@@ -35,7 +35,8 @@ module BusinessFlow
|
|
35
35
|
# Represents the result of a step, and allows setting response values on
|
36
36
|
# an object, and merging error data into the same object.
|
37
37
|
class Result
|
38
|
-
def initialize(result, output_map, output_callable)
|
38
|
+
def initialize(parameter_source, result, output_map, output_callable)
|
39
|
+
@parameter_source = parameter_source
|
39
40
|
@result = result
|
40
41
|
@output_map = output_map
|
41
42
|
@output_callable = output_callable
|
@@ -44,6 +45,7 @@ module BusinessFlow
|
|
44
45
|
def merge_into(object)
|
45
46
|
merge_errors_into(object)
|
46
47
|
merge_outputs_into(object)
|
48
|
+
output
|
47
49
|
end
|
48
50
|
|
49
51
|
def executed?
|
@@ -56,8 +58,14 @@ module BusinessFlow
|
|
56
58
|
@result.respond_to?(:errors?) ? @result.errors? : false
|
57
59
|
end
|
58
60
|
|
61
|
+
# :reek:ManualDispatch Checking respond_to? is signficantly faster than
|
62
|
+
# eating the NoMethodError when grabbing our error object.
|
63
|
+
def valid?
|
64
|
+
@result.respond_to?(:valid?) ? @result.valid? : true
|
65
|
+
end
|
66
|
+
|
59
67
|
def output
|
60
|
-
@
|
68
|
+
@parameter_source.instance_exec(@result, &@output_callable)
|
61
69
|
end
|
62
70
|
|
63
71
|
def self.process_output(object, output, output_setter)
|
@@ -71,8 +79,14 @@ module BusinessFlow
|
|
71
79
|
|
72
80
|
private
|
73
81
|
|
82
|
+
# :reek:ManualDispatch Checking respond_to? is signficantly faster than
|
83
|
+
# eating the NoMethodError when grabbing our error object.
|
84
|
+
def mergeable_errors?
|
85
|
+
@result.respond_to?(:errors) && errors? && !valid?
|
86
|
+
end
|
87
|
+
|
74
88
|
def merge_errors_into(object)
|
75
|
-
return unless
|
89
|
+
return unless mergeable_errors?
|
76
90
|
@result.errors.each do |attribute, message|
|
77
91
|
attribute = "#{@result.class.name.underscore}.#{attribute}"
|
78
92
|
(object.errors[attribute] << message).uniq!
|
@@ -103,8 +117,8 @@ module BusinessFlow
|
|
103
117
|
|
104
118
|
# Manage creating results for our step
|
105
119
|
ResultFactory = Struct.new(:outputs, :output_callable) do
|
106
|
-
def result(step_result)
|
107
|
-
Result.new(step_result, outputs, output_callable)
|
120
|
+
def result(step_result, parameter_source)
|
121
|
+
Result.new(parameter_source, step_result, outputs, output_callable)
|
108
122
|
end
|
109
123
|
end
|
110
124
|
|
@@ -163,7 +177,8 @@ module BusinessFlow
|
|
163
177
|
def call(parameter_source)
|
164
178
|
parameters = @input_object.parameters_from_source(parameter_source)
|
165
179
|
if @condition.call(parameter_source, parameters)
|
166
|
-
@result_factory.result(@callable.call(parameter_source, parameters)
|
180
|
+
@result_factory.result(@callable.call(parameter_source, parameters),
|
181
|
+
parameter_source)
|
167
182
|
else
|
168
183
|
ConditionFailedResult.new
|
169
184
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: business_flow
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.14.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alex Scarborough
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-03-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|