business_flow 0.2.0 → 0.3.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/base.rb +73 -64
- data/lib/business_flow/version.rb +1 -1
- data/lib/business_flow.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d9c94efd239befaaff61cf57d19cb6b275435d02
|
4
|
+
data.tar.gz: 944f1a4075af4781ea1ee873366c4900e5e26241
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2fc9b094b2677ed5e13ed1b17c58d07de5340bef3608540f6171783656d238a54346988361dd96bf94665b9730941edffd247d06c9fd9695355cb6822df9e01a
|
7
|
+
data.tar.gz: a3a9e27a570b2e14669521de739982abb05558723c7b820a22c1d60ccbbd76b6e4a5e8fb589cf08e6f224b5ce04d9d5322b2f1fa1d10cc9689c410b58cf4fd5c
|
data/Gemfile.lock
CHANGED
data/lib/business_flow/base.rb
CHANGED
@@ -8,88 +8,97 @@ module BusinessFlow
|
|
8
8
|
# Check output slots even if they're not going through our defined setter
|
9
9
|
# Conditional steps?
|
10
10
|
# ActiveSupport notifiers
|
11
|
-
|
12
|
-
|
13
|
-
|
11
|
+
module Base
|
12
|
+
def self.included(klass)
|
13
|
+
klass.include(DSL)
|
14
|
+
klass.prepend(InstanceMethods)
|
15
|
+
end
|
14
16
|
|
15
|
-
|
16
|
-
|
17
|
+
module InstanceMethods
|
18
|
+
attr_reader :parameter_object
|
19
|
+
private :parameter_object
|
17
20
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
+
def initialize(parameter_object)
|
22
|
+
@parameter_object = parameter_object
|
23
|
+
super()
|
24
|
+
end
|
21
25
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
+
def call
|
27
|
+
return if invalid?
|
28
|
+
if defined?(super)
|
29
|
+
super
|
30
|
+
else
|
31
|
+
process_steps
|
32
|
+
end
|
33
|
+
end
|
26
34
|
|
27
|
-
|
35
|
+
private
|
28
36
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
37
|
+
def process_steps
|
38
|
+
steps.each do |step_name|
|
39
|
+
catch(:halt_step) do
|
40
|
+
process_step(step_name)
|
41
|
+
end
|
42
|
+
break if errors.any?
|
33
43
|
end
|
34
|
-
break if errors.any?
|
35
44
|
end
|
36
|
-
end
|
37
45
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
46
|
+
def process_step(step)
|
47
|
+
input_object = marshall_input_object(step.inputs)
|
48
|
+
result = step.dispatch(self, input_object)
|
49
|
+
marshall_outputs(result, step.outputs) if result.present?
|
50
|
+
end
|
43
51
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
52
|
+
def marshall_input_object(input_object)
|
53
|
+
return self if input_object.blank?
|
54
|
+
Hash[input_object.map do |input_name, input_value|
|
55
|
+
[
|
56
|
+
input_name,
|
57
|
+
process_input(input_value)
|
58
|
+
]
|
59
|
+
end
|
60
|
+
]
|
61
|
+
end
|
54
62
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
63
|
+
def marshall_outputs(result, output_object)
|
64
|
+
merge_other_errors(result.errors, result.class.name.underscore)
|
65
|
+
output_object.each do |(output_name, output_setter)|
|
66
|
+
break if errors.any?
|
67
|
+
output = result.public_send(output_name)
|
68
|
+
process_output(output, output_setter)
|
69
|
+
end
|
61
70
|
end
|
62
|
-
end
|
63
71
|
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
72
|
+
def merge_other_errors(other_errors, base_name)
|
73
|
+
other_errors.each do |attribute, message|
|
74
|
+
attribute = "#{base_name}.#{attribute}"
|
75
|
+
(errors[attribute] << message).uniq!
|
76
|
+
end
|
68
77
|
end
|
69
|
-
end
|
70
78
|
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
+
def process_input(input_value)
|
80
|
+
case input_value
|
81
|
+
when Symbol
|
82
|
+
send(input_value)
|
83
|
+
when Proc
|
84
|
+
instance_exec(&input_value)
|
85
|
+
else
|
86
|
+
input_value
|
87
|
+
end
|
79
88
|
end
|
80
|
-
end
|
81
89
|
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
90
|
+
def process_output(output, output_setter)
|
91
|
+
case output_setter
|
92
|
+
when Symbol
|
93
|
+
send("#{output_setter}=", output)
|
94
|
+
when Proc
|
95
|
+
instance_exec(output, &output_setter)
|
96
|
+
end
|
88
97
|
end
|
89
|
-
end
|
90
98
|
|
91
|
-
|
92
|
-
|
99
|
+
def steps
|
100
|
+
self.class.step_queue || []
|
101
|
+
end
|
93
102
|
end
|
94
103
|
end
|
95
104
|
end
|
data/lib/business_flow.rb
CHANGED