flow_object 0.1.0 → 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 +3 -3
- data/flow_object.gemspec +1 -1
- data/lib/flow_object/base.rb +98 -73
- 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: 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
@@ -1,8 +1,8 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
flow_object (0.1.
|
5
|
-
mature_factory (~> 0.2.
|
4
|
+
flow_object (0.1.5)
|
5
|
+
mature_factory (~> 0.2.12)
|
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.12)
|
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.12'
|
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
@@ -13,99 +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.to(self.out)
|
19
|
+
def on_failure(failed_step = nil)
|
20
|
+
# NOOP
|
22
21
|
end
|
23
22
|
|
24
|
-
def
|
25
|
-
|
26
|
-
self
|
23
|
+
def on_success
|
24
|
+
# NOOP
|
27
25
|
end
|
28
26
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
27
|
+
module ClassMethods
|
28
|
+
def inherited(subclass)
|
29
|
+
super
|
30
|
+
subclass.from(self.in)
|
31
|
+
subclass.to(self.out)
|
32
|
+
end
|
33
33
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
public_send(:"new_#{self.in}_input_instance", *initial_values)
|
39
|
-
end
|
34
|
+
def from(input)
|
35
|
+
self.in = input
|
36
|
+
self
|
37
|
+
end
|
40
38
|
|
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
|
39
|
+
def to(output)
|
40
|
+
self.out = output
|
41
|
+
self
|
42
|
+
end
|
50
43
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
44
|
+
def accept(*values)
|
45
|
+
self.initial_values = values
|
46
|
+
self
|
47
|
+
end
|
55
48
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
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
|
62
83
|
end
|
63
84
|
end
|
64
|
-
end
|
65
85
|
|
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)
|
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)
|
75
91
|
end
|
76
|
-
end
|
77
92
|
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
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")
|
83
101
|
end
|
84
|
-
end
|
85
102
|
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
end
|
96
|
-
__fo_resolve_cascade__(cascade, previous_step, failure)
|
97
|
-
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
|
98
112
|
|
99
|
-
|
100
|
-
|
101
|
-
|
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
|
102
124
|
|
103
|
-
|
104
|
-
|
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
|
105
132
|
end
|
106
133
|
|
107
|
-
|
108
|
-
# NOOP
|
109
|
-
end
|
134
|
+
extend ClassMethods
|
110
135
|
end
|
111
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:
|
11
|
+
date: 2021-03-04 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.12
|
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.12
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|