flow_object 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/flow_object/base.rb +98 -74
- data/lib/flow_object/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: fcfa33b52598259445a736e3e46b7eedd2012bc5
|
4
|
+
data.tar.gz: 0f4b07df841d4e15bc50ecddd09e1ea15e652f3d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 84817e3b8c4f23f6958bdaf77cb197e37664e4c95b70df31713b012e4edb327d9407ab2856d76b61701829685ea45a7b3392653d99385d05fc47df3cadbd158e
|
7
|
+
data.tar.gz: bdbe490405595d43a22fd33b55a97f697c4ede5abc6777ffb044f68884ae1d702dd05c9118a1add981c31a0e161bb1758f6497215ce2832bbde275c3997a1d53
|
data/Gemfile.lock
CHANGED
data/lib/flow_object/base.rb
CHANGED
@@ -13,100 +13,124 @@ module FlowObject
|
|
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
17
|
end
|
18
18
|
|
19
|
-
def
|
20
|
-
|
21
|
-
subclass.from(self.in)
|
22
|
-
subclass.to(self.out)
|
19
|
+
def on_failure(failed_step = nil)
|
20
|
+
# NOOP
|
23
21
|
end
|
24
22
|
|
25
|
-
def
|
26
|
-
|
27
|
-
self
|
23
|
+
def on_success
|
24
|
+
# NOOP
|
28
25
|
end
|
29
26
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
27
|
+
module ClassMethods
|
28
|
+
def inherited(subclass)
|
29
|
+
super
|
30
|
+
subclass.from(self.in)
|
31
|
+
subclass.to(self.out)
|
32
|
+
end
|
34
33
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
public_send(:"new_#{self.in}_input_instance", *initial_values)
|
40
|
-
end
|
34
|
+
def from(input)
|
35
|
+
self.in = input
|
36
|
+
self
|
37
|
+
end
|
41
38
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
return unless self.respond_to?(:"#{self.out}_output_class")
|
47
|
-
output_class = public_send(:"#{self.out}_output_class")
|
48
|
-
return if output_class.nil?
|
49
|
-
public_send(:"new_#{self.out}_output_instance")
|
50
|
-
end
|
39
|
+
def to(output)
|
40
|
+
self.out = output
|
41
|
+
self
|
42
|
+
end
|
51
43
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
44
|
+
def accept(*values)
|
45
|
+
self.initial_values = values
|
46
|
+
self
|
47
|
+
end
|
56
48
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
49
|
+
def call(flow: :main)
|
50
|
+
__fo_resolve_cascade__(*__fo_process__(flow: flow))
|
51
|
+
end
|
52
|
+
|
53
|
+
def flow(name = :main, &block)
|
54
|
+
wrap(name, delegate: true, &block)
|
55
|
+
end
|
56
|
+
|
57
|
+
private
|
58
|
+
|
59
|
+
def halt_flow?(object, id)
|
60
|
+
!object.valid?
|
61
|
+
end
|
62
|
+
|
63
|
+
def __fo_process__(flow: :main)
|
64
|
+
failure, step_name = false, self.in
|
65
|
+
plan = __fo_build_flow__(flow, step_name, __fo_wrap_input__)
|
66
|
+
cascade = __fo_run_flow__(plan,
|
67
|
+
proc{|_,id| step_name = id.title},
|
68
|
+
proc{ failure = true })
|
69
|
+
[cascade, step_name, failure]
|
70
|
+
end
|
71
|
+
|
72
|
+
def __fo_build_flow__(flow, step_name, object)
|
73
|
+
public_send(:"build_#{flow}", step_name, object)
|
74
|
+
end
|
75
|
+
|
76
|
+
def __fo_run_flow__(plan, on_step, on_failure)
|
77
|
+
plan.call do |object, id|
|
78
|
+
on_step.call(object, id)
|
79
|
+
if halt_flow?(object, id)
|
80
|
+
on_failure.call(object, id)
|
81
|
+
throw :halt
|
82
|
+
end
|
63
83
|
end
|
64
84
|
end
|
65
|
-
end
|
66
85
|
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
elsif flow.respond_to?(:"on_#{step}_failure")
|
73
|
-
flow.public_send(:"on_#{step}_failure")
|
74
|
-
else
|
75
|
-
flow.on_failure(step)
|
86
|
+
def __fo_wrap_input__
|
87
|
+
return initial_values if self.in.nil?
|
88
|
+
input_class = public_send(:"#{self.in}_input_class")
|
89
|
+
return initial_values if input_class.nil?
|
90
|
+
public_send(:"new_#{self.in}_input_instance", *initial_values)
|
76
91
|
end
|
77
|
-
end
|
78
92
|
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
93
|
+
def __fo_wrap_output__
|
94
|
+
# rescue NoMethodError => ex
|
95
|
+
# "You have not define output class. Please add `output :#{self.out}`"
|
96
|
+
return if self.out.nil?
|
97
|
+
return unless self.respond_to?(:"#{self.out}_output_class")
|
98
|
+
output_class = public_send(:"#{self.out}_output_class")
|
99
|
+
return if output_class.nil?
|
100
|
+
public_send(:"new_#{self.out}_output_instance")
|
84
101
|
end
|
85
|
-
end
|
86
102
|
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
end
|
97
|
-
__fo_resolve_cascade__(cascade, previous_step, failure)
|
98
|
-
end
|
103
|
+
def __fo_resolve_cascade__(cascade, step, failure)
|
104
|
+
new(cascade).tap do |flow|
|
105
|
+
if failure
|
106
|
+
__fo_notify_error__(flow, step)
|
107
|
+
else
|
108
|
+
__fo_notify_success__(flow)
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
99
112
|
|
100
|
-
|
101
|
-
|
102
|
-
|
113
|
+
def __fo_notify_error__(flow, step)
|
114
|
+
if flow.output.respond_to?(:"on_#{step}_failure")
|
115
|
+
flow.output.public_send(:"on_#{step}_failure", flow.given)
|
116
|
+
elsif flow.output.respond_to?(:on_failure)
|
117
|
+
flow.output.on_failure(flow.given, step)
|
118
|
+
elsif flow.respond_to?(:"on_#{step}_failure")
|
119
|
+
flow.public_send(:"on_#{step}_failure")
|
120
|
+
else
|
121
|
+
flow.on_failure(step)
|
122
|
+
end
|
123
|
+
end
|
103
124
|
|
104
|
-
|
105
|
-
|
125
|
+
def __fo_notify_success__(flow)
|
126
|
+
if flow.output.respond_to?(:on_success)
|
127
|
+
flow.output.on_success(flow.given)
|
128
|
+
else
|
129
|
+
flow.on_success
|
130
|
+
end
|
131
|
+
end
|
106
132
|
end
|
107
133
|
|
108
|
-
|
109
|
-
# NOOP
|
110
|
-
end
|
134
|
+
extend ClassMethods
|
111
135
|
end
|
112
136
|
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.1.
|
4
|
+
version: 0.1.5
|
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-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mature_factory
|