flow_object 0.2.1 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +0 -0
- data/.rspec +0 -0
- data/.rubocop.yml +78 -0
- data/.ruby-version +1 -1
- data/.travis.yml +0 -0
- data/CODE_OF_CONDUCT.md +0 -0
- data/Gemfile +4 -2
- data/Gemfile.lock +35 -7
- data/LICENSE.txt +0 -0
- data/README.md +0 -0
- data/Rakefile +5 -3
- data/bin/console +4 -3
- data/flow_object.gemspec +9 -5
- data/lib/flow_object/base.rb +65 -52
- data/lib/flow_object/callbacks.rb +61 -17
- data/lib/flow_object/runner.rb +18 -41
- data/lib/flow_object/version.rb +3 -1
- data/lib/flow_object.rb +3 -1
- metadata +36 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: db5d4237447ea9da647afab9214f2a37e10e3446353933dd6dd9f929d1b4a021
|
4
|
+
data.tar.gz: 0ca51ffecc9b02fe9f6a92f9382b0a91d18812645e844cfc02e22dc95997e4a4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2fe85a38185bc79f41c3000ca80e8079578e591317dede9a2615a632a3e5756eb0c50b6f9a2def175bf781d50d9c00c50a645c2b623b8e8796a7904a3bb3dcf4
|
7
|
+
data.tar.gz: a63a10e4d35e722f28cb641711509653c44dfc0763c8cee77fc9f3da7b790f6bf49cf5c1a945dbedb395261aaa4d7e87096e071b8f4dd602c5f43d22b20111ff
|
data/.gitignore
CHANGED
File without changes
|
data/.rspec
CHANGED
File without changes
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
AllCops:
|
2
|
+
NewCops: enable
|
3
|
+
Exclude:
|
4
|
+
- flow_object.gemspec
|
5
|
+
Gemspec/DateAssignment: # (new in 1.10)
|
6
|
+
Enabled: true
|
7
|
+
Layout/SpaceBeforeBrackets: # (new in 1.7)
|
8
|
+
Enabled: true
|
9
|
+
Lint/AmbiguousAssignment: # (new in 1.7)
|
10
|
+
Enabled: true
|
11
|
+
Lint/DeprecatedConstants: # (new in 1.8)
|
12
|
+
Enabled: true
|
13
|
+
Lint/DuplicateBranch: # (new in 1.3)
|
14
|
+
Enabled: true
|
15
|
+
Lint/DuplicateRegexpCharacterClassElement: # (new in 1.1)
|
16
|
+
Enabled: true
|
17
|
+
Lint/EmptyBlock: # (new in 1.1)
|
18
|
+
Enabled: true
|
19
|
+
Exclude:
|
20
|
+
- lib/flow_object/callbacks.rb
|
21
|
+
Lint/EmptyClass: # (new in 1.3)
|
22
|
+
Enabled: true
|
23
|
+
Exclude:
|
24
|
+
- spec/**/*.rb
|
25
|
+
Lint/LambdaWithoutLiteralBlock: # (new in 1.8)
|
26
|
+
Enabled: true
|
27
|
+
Lint/NoReturnInBeginEndBlocks: # (new in 1.2)
|
28
|
+
Enabled: true
|
29
|
+
Lint/NumberedParameterAssignment: # (new in 1.9)
|
30
|
+
Enabled: true
|
31
|
+
Lint/OrAssignmentToConstant: # (new in 1.9)
|
32
|
+
Enabled: true
|
33
|
+
Lint/RedundantDirGlobSort: # (new in 1.8)
|
34
|
+
Enabled: true
|
35
|
+
Lint/SymbolConversion: # (new in 1.9)
|
36
|
+
Enabled: true
|
37
|
+
Lint/ToEnumArguments: # (new in 1.1)
|
38
|
+
Enabled: true
|
39
|
+
Lint/TripleQuotes: # (new in 1.9)
|
40
|
+
Enabled: true
|
41
|
+
Lint/UnexpectedBlockArity: # (new in 1.5)
|
42
|
+
Enabled: true
|
43
|
+
Lint/UnmodifiedReduceAccumulator: # (new in 1.1)
|
44
|
+
Enabled: true
|
45
|
+
Style/ArgumentsForwarding: # (new in 1.1)
|
46
|
+
Enabled: true
|
47
|
+
Style/CollectionCompact: # (new in 1.2)
|
48
|
+
Enabled: true
|
49
|
+
Style/DocumentDynamicEvalDefinition: # (new in 1.1)
|
50
|
+
Enabled: true
|
51
|
+
Style/EndlessMethod: # (new in 1.8)
|
52
|
+
Enabled: true
|
53
|
+
Style/HashConversion: # (new in 1.10)
|
54
|
+
Enabled: true
|
55
|
+
Style/HashExcept: # (new in 1.7)
|
56
|
+
Enabled: true
|
57
|
+
Style/IfWithBooleanLiteralBranches: # (new in 1.9)
|
58
|
+
Enabled: true
|
59
|
+
Style/NegatedIfElseCondition: # (new in 1.2)
|
60
|
+
Enabled: true
|
61
|
+
Style/NilLambda: # (new in 1.3)
|
62
|
+
Enabled: true
|
63
|
+
Style/RedundantArgument: # (new in 1.4)
|
64
|
+
Enabled: true
|
65
|
+
Style/StringChars: # (new in 1.12)
|
66
|
+
Enabled: true
|
67
|
+
Style/SwapValues: # (new in 1.1)
|
68
|
+
Enabled: true
|
69
|
+
Metrics/BlockLength:
|
70
|
+
Exclude:
|
71
|
+
- spec/**/*.rb
|
72
|
+
Naming/MethodParameterName:
|
73
|
+
Exclude:
|
74
|
+
- spec/**/*.rb
|
75
|
+
Style/Semicolon:
|
76
|
+
Exclude:
|
77
|
+
- spec/**/*.rb
|
78
|
+
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.
|
1
|
+
2.4.0
|
data/.travis.yml
CHANGED
File without changes
|
data/CODE_OF_CONDUCT.md
CHANGED
File without changes
|
data/Gemfile
CHANGED
@@ -1,6 +1,8 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
3
|
+
source 'https://rubygems.org'
|
4
|
+
|
5
|
+
git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
|
4
6
|
|
5
7
|
# Specify your gem's dependencies in flow_object.gemspec
|
6
8
|
gemspec
|
data/Gemfile.lock
CHANGED
@@ -1,23 +1,32 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
flow_object (0.
|
5
|
-
|
4
|
+
flow_object (0.3.1)
|
5
|
+
hospodar (~> 1)
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
9
9
|
specs:
|
10
|
+
ast (2.4.2)
|
10
11
|
coderay (1.1.3)
|
11
12
|
diff-lcs (1.4.4)
|
12
|
-
|
13
|
-
|
13
|
+
docile (1.3.5)
|
14
|
+
dry-inflector (0.2.0)
|
15
|
+
hospodar (1.0.1)
|
14
16
|
dry-inflector (~> 0.1)
|
15
|
-
|
17
|
+
json (2.5.1)
|
16
18
|
method_source (1.0.0)
|
19
|
+
dry-inflector (~> 0.1)
|
20
|
+
parallel (1.20.1)
|
21
|
+
parser (3.0.2.0)
|
22
|
+
ast (~> 2.4.1)
|
17
23
|
pry (0.13.1)
|
18
24
|
coderay (~> 1.1)
|
19
25
|
method_source (~> 1.0)
|
26
|
+
rainbow (3.0.0)
|
20
27
|
rake (10.5.0)
|
28
|
+
regexp_parser (2.1.1)
|
29
|
+
rexml (3.2.5)
|
21
30
|
rspec (3.9.0)
|
22
31
|
rspec-core (~> 3.9.0)
|
23
32
|
rspec-expectations (~> 3.9.0)
|
@@ -33,7 +42,24 @@ GEM
|
|
33
42
|
rspec-support (3.9.3)
|
34
43
|
rspec_vars_helper (0.1.0)
|
35
44
|
rspec (>= 2.4)
|
36
|
-
|
45
|
+
rubocop (1.12.1)
|
46
|
+
parallel (~> 1.10)
|
47
|
+
parser (>= 3.0.0.0)
|
48
|
+
rainbow (>= 2.2.2, < 4.0)
|
49
|
+
regexp_parser (>= 1.8, < 3.0)
|
50
|
+
rexml
|
51
|
+
rubocop-ast (>= 1.2.0, < 2.0)
|
52
|
+
ruby-progressbar (~> 1.7)
|
53
|
+
unicode-display_width (>= 1.4.0, < 3.0)
|
54
|
+
rubocop-ast (1.4.1)
|
55
|
+
parser (>= 2.7.1.5)
|
56
|
+
ruby-progressbar (1.11.0)
|
57
|
+
simplecov (0.17.0)
|
58
|
+
docile (~> 1.1)
|
59
|
+
json (>= 1.8, < 3)
|
60
|
+
simplecov-html (~> 0.10.0)
|
61
|
+
simplecov-html (0.10.2)
|
62
|
+
unicode-display_width (2.0.0)
|
37
63
|
|
38
64
|
PLATFORMS
|
39
65
|
ruby
|
@@ -45,6 +71,8 @@ DEPENDENCIES
|
|
45
71
|
rake (~> 10.0)
|
46
72
|
rspec (~> 3.0)
|
47
73
|
rspec_vars_helper (~> 0.1)
|
74
|
+
rubocop
|
75
|
+
simplecov (= 0.17)
|
48
76
|
|
49
77
|
BUNDLED WITH
|
50
|
-
1.17.
|
78
|
+
1.17.3
|
data/LICENSE.txt
CHANGED
File without changes
|
data/README.md
CHANGED
File without changes
|
data/Rakefile
CHANGED
data/bin/console
CHANGED
@@ -1,13 +1,14 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
|
-
require
|
4
|
-
require
|
4
|
+
require 'bundler/setup'
|
5
|
+
require 'flow_object'
|
5
6
|
|
6
7
|
# You can add fixtures and/or initialization code here to make experimenting
|
7
8
|
# with your gem easier. You can also use a different console, if you like.
|
8
9
|
|
9
10
|
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
-
require
|
11
|
+
require 'pry'
|
11
12
|
Pry.start
|
12
13
|
|
13
14
|
# require "irb"
|
data/flow_object.gemspec
CHANGED
@@ -1,5 +1,6 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
|
2
|
-
lib = File.expand_path(
|
3
|
+
lib = File.expand_path('lib', __dir__)
|
3
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
5
|
require 'flow_object/version'
|
5
6
|
|
@@ -9,10 +10,11 @@ Gem::Specification.new do |spec|
|
|
9
10
|
spec.authors = ['Andrii Baran']
|
10
11
|
spec.email = ['andriy.baran.v@gmail.com']
|
11
12
|
|
12
|
-
spec.summary =
|
13
|
-
spec.description =
|
13
|
+
spec.summary = 'Create objects for storing application flows'
|
14
|
+
spec.description = 'General purpose software library designed for happiness'
|
14
15
|
spec.homepage = 'https://github.com/andriy-baran/flow_object'
|
15
16
|
spec.license = 'MIT'
|
17
|
+
spec.required_ruby_version = Gem::Requirement.new('>= 2.4.0')
|
16
18
|
|
17
19
|
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
18
20
|
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
@@ -29,18 +31,20 @@ Gem::Specification.new do |spec|
|
|
29
31
|
|
30
32
|
# Specify which files should be added to the gem when it is released.
|
31
33
|
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
32
|
-
spec.files
|
34
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
33
35
|
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
34
36
|
end
|
35
37
|
spec.bindir = 'exe'
|
36
38
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
37
39
|
spec.require_paths = ['lib']
|
38
40
|
|
39
|
-
spec.add_dependency '
|
41
|
+
spec.add_dependency 'hospodar', '~> 1'
|
40
42
|
|
41
43
|
spec.add_development_dependency 'bundler', '~> 1.17'
|
42
44
|
spec.add_development_dependency 'pry'
|
43
45
|
spec.add_development_dependency 'rake', '~> 10.0'
|
44
46
|
spec.add_development_dependency 'rspec', '~> 3.0'
|
45
47
|
spec.add_development_dependency 'rspec_vars_helper', '~> 0.1'
|
48
|
+
spec.add_development_dependency 'rubocop'
|
49
|
+
spec.add_development_dependency 'simplecov', '0.17'
|
46
50
|
end
|
data/lib/flow_object/base.rb
CHANGED
@@ -1,23 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module FlowObject
|
4
|
+
# Provides DSL for flows definitions
|
2
5
|
class Base
|
3
|
-
include
|
4
|
-
include
|
6
|
+
include Hospodar
|
7
|
+
include Hospodar::Builder
|
5
8
|
|
6
9
|
produces :stages, :inputs, :outputs
|
7
10
|
|
8
11
|
class << self
|
9
|
-
|
10
|
-
attr_reader :in, :out, :initial_values
|
11
|
-
def_delegators :callbacks, :after_input_initialize, :after_flow_initialize,
|
12
|
-
:after_input_check, :after_flow_check, :after_output_initialize
|
12
|
+
attr_reader :in, :out
|
13
13
|
end
|
14
14
|
|
15
|
-
|
15
|
+
extend Forwardable
|
16
|
+
def_delegators :callbacks, :output_initialized
|
17
|
+
|
18
|
+
attr_reader :output, :callbacks
|
16
19
|
|
17
|
-
def initialize(flow, step_name = :flow)
|
18
|
-
@output = self.class.send(:
|
19
|
-
|
20
|
-
|
20
|
+
def initialize(flow, callbacks, step_name = :flow)
|
21
|
+
@output = self.class.send(:fo_wrap_output)
|
22
|
+
@callbacks = callbacks
|
23
|
+
Hospodar::Builder.def_accessor(step_name, on: @output, to: flow, delegate: true)
|
24
|
+
output_initialized.call(@output)
|
25
|
+
end
|
26
|
+
|
27
|
+
def on_exception(exception = nil)
|
28
|
+
# NOOP
|
21
29
|
end
|
22
30
|
|
23
31
|
def on_failure(failed_step = nil)
|
@@ -28,20 +36,12 @@ module FlowObject
|
|
28
36
|
# NOOP
|
29
37
|
end
|
30
38
|
|
39
|
+
# Class-level interface for flow objects
|
31
40
|
module ClassMethods
|
32
41
|
def inherited(subclass)
|
33
42
|
super
|
34
43
|
subclass.from(self.in)
|
35
|
-
subclass.to(
|
36
|
-
subclass.after_input_initialize(&self.after_input_initialize)
|
37
|
-
subclass.after_flow_initialize(&self.after_flow_initialize)
|
38
|
-
subclass.after_input_check(&self.after_input_check)
|
39
|
-
subclass.after_flow_check(&self.after_flow_check)
|
40
|
-
subclass.after_output_initialize(&self.after_output_initialize)
|
41
|
-
end
|
42
|
-
|
43
|
-
def callbacks
|
44
|
-
@callbacks ||= Callbacks.new
|
44
|
+
subclass.to(out)
|
45
45
|
end
|
46
46
|
|
47
47
|
def from(input)
|
@@ -54,67 +54,80 @@ module FlowObject
|
|
54
54
|
self
|
55
55
|
end
|
56
56
|
|
57
|
-
def
|
58
|
-
|
59
|
-
self
|
60
|
-
end
|
61
|
-
|
62
|
-
def call(flow: :main)
|
63
|
-
__fo_resolve__(__fo_process__(flow: flow))
|
57
|
+
def call(input:, flow: :main, &block)
|
58
|
+
fo_resolve(fo_process(input, flow: flow, &block))
|
64
59
|
end
|
65
60
|
|
66
61
|
def flow(name = :main, &block)
|
67
|
-
wrap(name, delegate: true, &block)
|
68
|
-
end
|
69
|
-
|
70
|
-
def link_with_delegation(target, object, accessor, delegate)
|
71
|
-
MatureFactory::Features::Assemble::AbstractBuilder
|
72
|
-
.link_with_delegation(target, object, accessor, delegate)
|
62
|
+
wrap(name, delegate: true, on_exception: :halt, &block)
|
73
63
|
end
|
74
64
|
|
75
65
|
private
|
76
66
|
|
77
|
-
def halt_flow?(
|
67
|
+
def halt_flow?(_object, _id)
|
78
68
|
false
|
79
69
|
end
|
80
70
|
|
81
|
-
def
|
82
|
-
plan
|
71
|
+
def fo_process(input, flow: :main, &block)
|
72
|
+
plan = fo_build_flow(flow, self.in, :input, fo_wrap_input(input))
|
73
|
+
callbacks = Callbacks.new(@callbacks_allowlist)
|
74
|
+
block.call(callbacks) if block_given?
|
83
75
|
Runner.new(plan, callbacks, method(:halt_flow?)).execute_plan
|
84
76
|
end
|
85
77
|
|
86
|
-
def
|
87
|
-
|
78
|
+
def fo_build_flow(flow, step_name, group, object)
|
79
|
+
plan = send(:"hospodar_perform_planing_for_#{flow}", object, step_name, group)
|
80
|
+
@callbacks_allowlist = plan.map(&:last).map(&:to_sym) + [:"#{out}_output"]
|
81
|
+
send(:"hospodar_execute_plan_for_#{flow}", plan)
|
88
82
|
end
|
89
83
|
|
90
|
-
def
|
84
|
+
def fo_wrap_input(*initial_values)
|
91
85
|
return initial_values if self.in.nil?
|
86
|
+
|
92
87
|
input_class = public_send(:"#{self.in}_input_class")
|
93
88
|
return initial_values if input_class.nil?
|
89
|
+
|
94
90
|
public_send(:"new_#{self.in}_input_instance", *initial_values)
|
95
91
|
end
|
96
92
|
|
97
|
-
def
|
93
|
+
def fo_wrap_output
|
98
94
|
# rescue NoMethodError => ex
|
99
95
|
# "You have not define output class. Please add `output :#{self.out}`"
|
100
|
-
return if
|
101
|
-
return unless
|
102
|
-
|
96
|
+
return if out.nil?
|
97
|
+
return unless respond_to?(:"#{out}_output_class")
|
98
|
+
|
99
|
+
output_class = public_send(:"#{out}_output_class")
|
103
100
|
return if output_class.nil?
|
104
|
-
|
101
|
+
|
102
|
+
public_send(:"new_#{out}_output_instance")
|
105
103
|
end
|
106
104
|
|
107
|
-
def
|
108
|
-
new(runner.flow, runner.step_name).tap do |handler|
|
109
|
-
if runner.
|
110
|
-
|
105
|
+
def fo_resolve(runner)
|
106
|
+
new(runner.flow.public_send(runner.step_name), runner.callbacks, runner.step_name).tap do |handler|
|
107
|
+
if runner.flow.exceptional?
|
108
|
+
fo_notify_exception(handler, runner.flow.exception)
|
109
|
+
elsif runner.failure
|
110
|
+
fo_notify_error(handler, runner.step_name)
|
111
111
|
else
|
112
|
-
|
112
|
+
fo_notify_success(handler)
|
113
113
|
end
|
114
114
|
end
|
115
115
|
end
|
116
116
|
|
117
|
-
def
|
117
|
+
def fo_notify_exception(handler, exception)
|
118
|
+
callback = :"on_#{exception.step_id.title}_exception"
|
119
|
+
if handler.output.respond_to?(callback)
|
120
|
+
handler.output.public_send(callback, exception)
|
121
|
+
elsif handler.output.respond_to?(:on_exception)
|
122
|
+
handler.output.on_exception(exception)
|
123
|
+
elsif handler.respond_to?(callback)
|
124
|
+
handler.public_send(callback, exception)
|
125
|
+
else
|
126
|
+
handler.on_exception(exception)
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
def fo_notify_error(handler, step)
|
118
131
|
if handler.output.respond_to?(:"on_#{step}_failure")
|
119
132
|
handler.output.public_send(:"on_#{step}_failure")
|
120
133
|
elsif handler.output.respond_to?(:on_failure)
|
@@ -126,7 +139,7 @@ module FlowObject
|
|
126
139
|
end
|
127
140
|
end
|
128
141
|
|
129
|
-
def
|
142
|
+
def fo_notify_success(handler)
|
130
143
|
if handler.output.respond_to?(:on_success)
|
131
144
|
handler.output.on_success
|
132
145
|
else
|
@@ -1,29 +1,73 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module FlowObject
|
4
|
+
# Storage for users callbacks
|
2
5
|
class Callbacks
|
3
|
-
SUPPORTED = %i[
|
4
|
-
after_input_initialize
|
5
|
-
after_flow_initialize
|
6
|
-
after_input_check
|
7
|
-
after_flow_check
|
8
|
-
after_output_initialize
|
9
|
-
].freeze
|
10
|
-
|
11
6
|
NOOP = proc {}.freeze
|
12
7
|
|
13
|
-
|
14
|
-
|
8
|
+
Iteration = Struct.new(:idx, :type, :list_size) do
|
9
|
+
def output_checked?
|
10
|
+
output? && checked?
|
11
|
+
end
|
12
|
+
|
13
|
+
def generic_alias
|
14
|
+
return :"input_#{type}" if input?
|
15
|
+
return :flow_initialized if flow_initialized?
|
16
|
+
return :flow_checked if flow_checked?
|
17
|
+
return :output_initialized if output_initialized?
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def flow_initialized?
|
23
|
+
idx == 1 && initialized?
|
24
|
+
end
|
25
|
+
|
26
|
+
def flow_checked?
|
27
|
+
idx == list_size - 2 && checked?
|
28
|
+
end
|
29
|
+
|
30
|
+
def output_initialized?
|
31
|
+
output? && initialized?
|
32
|
+
end
|
33
|
+
|
34
|
+
def input?
|
35
|
+
idx.zero?
|
36
|
+
end
|
37
|
+
|
38
|
+
def initialized?
|
39
|
+
type == :initialized
|
40
|
+
end
|
41
|
+
|
42
|
+
def checked?
|
43
|
+
type == :checked
|
44
|
+
end
|
45
|
+
|
46
|
+
def output?
|
47
|
+
idx == list_size - 1
|
48
|
+
end
|
15
49
|
end
|
16
50
|
|
17
|
-
def
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
51
|
+
def initialize(list)
|
52
|
+
@callbacks = Hash.new { |hash, key| hash[key] = NOOP }
|
53
|
+
each_callback(list) do |callback, callback_alias|
|
54
|
+
define_singleton_method(callback) do |&block|
|
55
|
+
block.nil? ? @callbacks[callback] : @callbacks[callback] = block
|
56
|
+
end
|
57
|
+
singleton_class.class_eval { alias_method(callback_alias, callback) } if callback_alias
|
22
58
|
end
|
23
59
|
end
|
24
60
|
|
25
|
-
|
26
|
-
|
61
|
+
private
|
62
|
+
|
63
|
+
def each_callback(list)
|
64
|
+
list_size = list.size
|
65
|
+
list.each.with_index do |method_name, idx|
|
66
|
+
{ initialized: :"#{method_name}_initialized", checked: :"#{method_name}_checked" }.each do |type, callback|
|
67
|
+
callback_alias = Iteration.new(idx, type, list_size).generic_alias
|
68
|
+
yield(callback, callback_alias)
|
69
|
+
end
|
70
|
+
end
|
27
71
|
end
|
28
72
|
end
|
29
73
|
end
|
data/lib/flow_object/runner.rb
CHANGED
@@ -1,6 +1,9 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module FlowObject
|
4
|
+
# Triggers flow execution and users callbacks
|
2
5
|
class Runner
|
3
|
-
attr_reader :step_name, :failure, :flow
|
6
|
+
attr_reader :step_name, :failure, :flow, :callbacks
|
4
7
|
|
5
8
|
def initialize(plan, callbacks, halt_if_proc)
|
6
9
|
@plan = plan
|
@@ -8,60 +11,34 @@ module FlowObject
|
|
8
11
|
@failure = false
|
9
12
|
@step_name = nil
|
10
13
|
@callbacks = callbacks
|
11
|
-
@step_index = 0
|
12
14
|
@halt_if_proc = halt_if_proc
|
13
15
|
end
|
14
16
|
|
15
17
|
def execute_plan
|
16
|
-
@flow =
|
17
|
-
after_flow_check(flow.public_send(@step_name))
|
18
|
+
@flow = flow_builder.call
|
18
19
|
self
|
19
20
|
end
|
20
21
|
|
21
22
|
private
|
22
23
|
|
23
|
-
def
|
24
|
-
@plan.
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
def after_flow_check(object)
|
30
|
-
@callbacks.after_flow_check.call(object)
|
31
|
-
end
|
32
|
-
|
33
|
-
def after_input_initialize(object)
|
34
|
-
@callbacks.after_input_initialize.call(object)
|
35
|
-
end
|
24
|
+
def flow_builder
|
25
|
+
@plan.do_until do |object, id|
|
26
|
+
@step_name = id.title
|
27
|
+
after_initialize(object, id)
|
28
|
+
@failure = @halt_if_proc.call(object, id)
|
29
|
+
next true if @failure
|
36
30
|
|
37
|
-
|
38
|
-
|
39
|
-
end
|
40
|
-
|
41
|
-
def after_input_check(object)
|
42
|
-
@callbacks.after_input_check.call(object)
|
43
|
-
end
|
44
|
-
|
45
|
-
def second_step?
|
46
|
-
@step_index == 1
|
47
|
-
end
|
48
|
-
|
49
|
-
def input_step?(id)
|
50
|
-
id.group == :input
|
31
|
+
after_check(object, id)
|
32
|
+
end
|
51
33
|
end
|
52
34
|
|
53
|
-
def
|
54
|
-
id.
|
35
|
+
def after_initialize(object, id)
|
36
|
+
@callbacks.public_send(:"#{id}_initialized").call(object)
|
55
37
|
end
|
56
38
|
|
57
|
-
def
|
58
|
-
|
59
|
-
|
60
|
-
@step_name = id.title
|
61
|
-
@step_index += 1
|
62
|
-
yield if @failure = @halt_if_proc.call(object, id)
|
63
|
-
after_input_check(object) if input_step?(id)
|
39
|
+
def after_check(object, id)
|
40
|
+
@callbacks.public_send(:"#{id}_checked").call(object)
|
41
|
+
false
|
64
42
|
end
|
65
|
-
|
66
43
|
end
|
67
44
|
end
|
data/lib/flow_object/version.rb
CHANGED
data/lib/flow_object.rb
CHANGED
metadata
CHANGED
@@ -1,29 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: flow_object
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.1
|
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-11-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: hospodar
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: '1'
|
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:
|
26
|
+
version: '1'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -94,6 +94,34 @@ dependencies:
|
|
94
94
|
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0.1'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rubocop
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: simplecov
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - '='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0.17'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - '='
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0.17'
|
97
125
|
description: General purpose software library designed for happiness
|
98
126
|
email:
|
99
127
|
- andriy.baran.v@gmail.com
|
@@ -103,6 +131,7 @@ extra_rdoc_files: []
|
|
103
131
|
files:
|
104
132
|
- ".gitignore"
|
105
133
|
- ".rspec"
|
134
|
+
- ".rubocop.yml"
|
106
135
|
- ".ruby-version"
|
107
136
|
- ".travis.yml"
|
108
137
|
- CODE_OF_CONDUCT.md
|
@@ -134,15 +163,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
134
163
|
requirements:
|
135
164
|
- - ">="
|
136
165
|
- !ruby/object:Gem::Version
|
137
|
-
version:
|
166
|
+
version: 2.4.0
|
138
167
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
139
168
|
requirements:
|
140
169
|
- - ">="
|
141
170
|
- !ruby/object:Gem::Version
|
142
171
|
version: '0'
|
143
172
|
requirements: []
|
144
|
-
|
145
|
-
rubygems_version: 2.5.1
|
173
|
+
rubygems_version: 3.2.30
|
146
174
|
signing_key:
|
147
175
|
specification_version: 4
|
148
176
|
summary: Create objects for storing application flows
|