flow_object 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +3 -3
- data/flow_object.gemspec +1 -1
- data/lib/flow_object/base.rb +133 -74
- data/lib/flow_object/version.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0c4e0bf60b9bd1664f1e627b21f7ab1f9054abba
|
4
|
+
data.tar.gz: e8e9520592e1e9cc689c15be26d744580c774396
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8edbfe815c46426494dfb7343f9f9d553e4f5889e79af5d7f09b2cd7202677cef7106c2b1ea6c5eb4892b3be24b6c6422465080c61db58b59f695a5511a1d054
|
7
|
+
data.tar.gz: b57d9c98ce427889d725c8297eadde4c3c190512ed9a9c54b8e2bf0ba224eafb785373cbedb0de56ae62729c4b40006323abad8ac042658d11c455c9373f95b0
|
data/Gemfile.lock
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
flow_object (0.
|
5
|
-
mature_factory (~> 0.2.
|
4
|
+
flow_object (0.2.0)
|
5
|
+
mature_factory (~> 0.2.13)
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
@@ -10,7 +10,7 @@ GEM
|
|
10
10
|
coderay (1.1.3)
|
11
11
|
diff-lcs (1.4.4)
|
12
12
|
dry-inflector (0.1.2)
|
13
|
-
mature_factory (0.2.
|
13
|
+
mature_factory (0.2.13)
|
14
14
|
dry-inflector (~> 0.1)
|
15
15
|
simple_facade (~> 0.2)
|
16
16
|
method_source (1.0.0)
|
data/flow_object.gemspec
CHANGED
@@ -36,7 +36,7 @@ Gem::Specification.new do |spec|
|
|
36
36
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
37
37
|
spec.require_paths = ['lib']
|
38
38
|
|
39
|
-
spec.add_dependency 'mature_factory', '~> 0.2.
|
39
|
+
spec.add_dependency 'mature_factory', '~> 0.2.13'
|
40
40
|
|
41
41
|
spec.add_development_dependency 'bundler', '~> 1.17'
|
42
42
|
spec.add_development_dependency 'pry'
|
data/lib/flow_object/base.rb
CHANGED
@@ -6,106 +6,165 @@ module FlowObject
|
|
6
6
|
composed_of :stages, :inputs, :outputs
|
7
7
|
|
8
8
|
class << self
|
9
|
-
|
9
|
+
attr_reader :in, :out, :initial_values
|
10
10
|
end
|
11
11
|
|
12
12
|
attr_reader :output, :given
|
13
13
|
|
14
14
|
def initialize(given)
|
15
15
|
@given = given
|
16
|
-
@output = self.class.__fo_wrap_output__
|
16
|
+
@output = self.class.send(:__fo_wrap_output__)
|
17
|
+
self.class.after_output_initialize.call(@output) if self.class.after_output_initialize
|
17
18
|
end
|
18
19
|
|
19
|
-
def
|
20
|
-
|
21
|
-
subclass.to(self.out)
|
20
|
+
def on_failure(failed_step = nil)
|
21
|
+
# NOOP
|
22
22
|
end
|
23
23
|
|
24
|
-
def
|
25
|
-
|
26
|
-
self
|
24
|
+
def on_success
|
25
|
+
# NOOP
|
27
26
|
end
|
28
27
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
28
|
+
module ClassMethods
|
29
|
+
def inherited(subclass)
|
30
|
+
super
|
31
|
+
subclass.from(self.in)
|
32
|
+
subclass.to(self.out)
|
33
|
+
subclass.after_input_initialize(&self.after_input_initialize)
|
34
|
+
subclass.after_flow_initialize(&self.after_flow_initialize)
|
35
|
+
subclass.after_input_check(&self.after_input_check)
|
36
|
+
subclass.after_flow_check(&self.after_flow_check)
|
37
|
+
subclass.after_output_initialize(&self.after_output_initialize)
|
38
|
+
end
|
33
39
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
public_send(:"new_#{self.in}_input_instance", *initial_values)
|
39
|
-
end
|
40
|
+
def from(input)
|
41
|
+
@in = input
|
42
|
+
self
|
43
|
+
end
|
40
44
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
return unless self.respond_to?(:"#{self.out}_output_class")
|
46
|
-
output_class = public_send(:"#{self.out}_output_class")
|
47
|
-
return if output_class.nil?
|
48
|
-
public_send(:"new_#{self.out}_output_instance")
|
49
|
-
end
|
45
|
+
def to(output)
|
46
|
+
@out = output
|
47
|
+
self
|
48
|
+
end
|
50
49
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
50
|
+
def accept(*values)
|
51
|
+
@initial_values = values
|
52
|
+
self
|
53
|
+
end
|
55
54
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
55
|
+
def call(flow: :main)
|
56
|
+
__fo_resolve_cascade__(*__fo_process__(flow: flow))
|
57
|
+
end
|
58
|
+
|
59
|
+
def flow(name = :main, &block)
|
60
|
+
wrap(name, delegate: true, &block)
|
61
|
+
end
|
62
|
+
|
63
|
+
def after_input_initialize(&block)
|
64
|
+
block_given? ? @after_input_initialize = block : @after_input_initialize
|
65
|
+
end
|
66
|
+
|
67
|
+
def after_flow_initialize(&block)
|
68
|
+
block_given? ? @after_flow_initialize = block : @after_flow_initialize
|
69
|
+
end
|
70
|
+
|
71
|
+
def after_input_check(&block)
|
72
|
+
block_given? ? @after_input_check = block : @after_input_check
|
73
|
+
end
|
74
|
+
|
75
|
+
def after_flow_check(&block)
|
76
|
+
block_given? ? @after_flow_check = block : @after_flow_check
|
77
|
+
end
|
78
|
+
|
79
|
+
def after_output_initialize(&block)
|
80
|
+
block_given? ? @after_output_initialize = block : @after_output_initialize
|
81
|
+
end
|
82
|
+
|
83
|
+
private
|
84
|
+
|
85
|
+
def halt_flow?(object, id)
|
86
|
+
false
|
87
|
+
end
|
88
|
+
|
89
|
+
def __fo_process__(flow: :main)
|
90
|
+
failure, step_name, group = false, self.in, :input
|
91
|
+
plan = __fo_build_flow__(flow, step_name, group, __fo_wrap_input__)
|
92
|
+
cascade = __fo_run_flow__(plan,
|
93
|
+
proc{|_,id| step_name = id.title},
|
94
|
+
proc{ failure = true },
|
95
|
+
after_input_initialize,
|
96
|
+
after_flow_initialize)
|
97
|
+
after_flow_check.call(cascade.public_send(step_name)) if after_flow_check
|
98
|
+
[cascade, step_name, failure]
|
99
|
+
end
|
100
|
+
|
101
|
+
def __fo_build_flow__(flow, step_name, group, object)
|
102
|
+
public_send(:"build_#{flow}", title: step_name, group: group, object: object)
|
103
|
+
end
|
104
|
+
|
105
|
+
def __fo_run_flow__(plan, on_step, on_failure, on_input, on_flow)
|
106
|
+
step_index = 0
|
107
|
+
plan.call do |object, id|
|
108
|
+
on_input.call(object) if on_input && id.group == :input
|
109
|
+
on_flow.call(object) if step_index == 1 && on_flow && id.group == :stage
|
110
|
+
on_step.call(object, id)
|
111
|
+
step_index += 1
|
112
|
+
if halt_flow?(object, id)
|
113
|
+
on_failure.call(object, id)
|
114
|
+
throw :halt
|
115
|
+
end
|
116
|
+
after_input_check.call(object) if after_input_check && id.group == :input
|
62
117
|
end
|
63
118
|
end
|
64
|
-
end
|
65
119
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
elsif flow.respond_to?(:"on_#{step}_failure")
|
72
|
-
flow.public_send(:"on_#{step}_failure")
|
73
|
-
else
|
74
|
-
flow.on_failure(step)
|
120
|
+
def __fo_wrap_input__
|
121
|
+
return initial_values if self.in.nil?
|
122
|
+
input_class = public_send(:"#{self.in}_input_class")
|
123
|
+
return initial_values if input_class.nil?
|
124
|
+
public_send(:"new_#{self.in}_input_instance", *initial_values)
|
75
125
|
end
|
76
|
-
end
|
77
126
|
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
127
|
+
def __fo_wrap_output__
|
128
|
+
# rescue NoMethodError => ex
|
129
|
+
# "You have not define output class. Please add `output :#{self.out}`"
|
130
|
+
return if self.out.nil?
|
131
|
+
return unless self.respond_to?(:"#{self.out}_output_class")
|
132
|
+
output_class = public_send(:"#{self.out}_output_class")
|
133
|
+
return if output_class.nil?
|
134
|
+
public_send(:"new_#{self.out}_output_instance")
|
83
135
|
end
|
84
|
-
end
|
85
136
|
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
end
|
96
|
-
__fo_resolve_cascade__(cascade, previous_step, failure)
|
97
|
-
end
|
137
|
+
def __fo_resolve_cascade__(cascade, step, failure)
|
138
|
+
new(cascade).tap do |flow|
|
139
|
+
if failure
|
140
|
+
__fo_notify_error__(flow, step)
|
141
|
+
else
|
142
|
+
__fo_notify_success__(flow)
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|
98
146
|
|
99
|
-
|
100
|
-
|
101
|
-
|
147
|
+
def __fo_notify_error__(flow, step)
|
148
|
+
if flow.output.respond_to?(:"on_#{step}_failure")
|
149
|
+
flow.output.public_send(:"on_#{step}_failure", flow.given)
|
150
|
+
elsif flow.output.respond_to?(:on_failure)
|
151
|
+
flow.output.on_failure(flow.given, step)
|
152
|
+
elsif flow.respond_to?(:"on_#{step}_failure")
|
153
|
+
flow.public_send(:"on_#{step}_failure")
|
154
|
+
else
|
155
|
+
flow.on_failure(step)
|
156
|
+
end
|
157
|
+
end
|
102
158
|
|
103
|
-
|
104
|
-
|
159
|
+
def __fo_notify_success__(flow)
|
160
|
+
if flow.output.respond_to?(:on_success)
|
161
|
+
flow.output.on_success(flow.given)
|
162
|
+
else
|
163
|
+
flow.on_success
|
164
|
+
end
|
165
|
+
end
|
105
166
|
end
|
106
167
|
|
107
|
-
|
108
|
-
# NOOP
|
109
|
-
end
|
168
|
+
extend ClassMethods
|
110
169
|
end
|
111
170
|
end
|
data/lib/flow_object/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: flow_object
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrii Baran
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-03-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mature_factory
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0.2.
|
19
|
+
version: 0.2.13
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 0.2.
|
26
|
+
version: 0.2.13
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|