flow_object 0.1.5 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fcfa33b52598259445a736e3e46b7eedd2012bc5
4
- data.tar.gz: 0f4b07df841d4e15bc50ecddd09e1ea15e652f3d
3
+ metadata.gz: 0c4e0bf60b9bd1664f1e627b21f7ab1f9054abba
4
+ data.tar.gz: e8e9520592e1e9cc689c15be26d744580c774396
5
5
  SHA512:
6
- metadata.gz: 84817e3b8c4f23f6958bdaf77cb197e37664e4c95b70df31713b012e4edb327d9407ab2856d76b61701829685ea45a7b3392653d99385d05fc47df3cadbd158e
7
- data.tar.gz: bdbe490405595d43a22fd33b55a97f697c4ede5abc6777ffb044f68884ae1d702dd05c9118a1add981c31a0e161bb1758f6497215ce2832bbde275c3997a1d53
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.1.5)
5
- mature_factory (~> 0.2.12)
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.12)
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.12'
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'
@@ -6,7 +6,7 @@ module FlowObject
6
6
  composed_of :stages, :inputs, :outputs
7
7
 
8
8
  class << self
9
- attr_accessor :in, :out, :initial_values
9
+ attr_reader :in, :out, :initial_values
10
10
  end
11
11
 
12
12
  attr_reader :output, :given
@@ -14,6 +14,7 @@ module FlowObject
14
14
  def initialize(given)
15
15
  @given = given
16
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
20
  def on_failure(failed_step = nil)
@@ -29,20 +30,25 @@ module FlowObject
29
30
  super
30
31
  subclass.from(self.in)
31
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)
32
38
  end
33
39
 
34
40
  def from(input)
35
- self.in = input
41
+ @in = input
36
42
  self
37
43
  end
38
44
 
39
45
  def to(output)
40
- self.out = output
46
+ @out = output
41
47
  self
42
48
  end
43
49
 
44
50
  def accept(*values)
45
- self.initial_values = values
51
+ @initial_values = values
46
52
  self
47
53
  end
48
54
 
@@ -54,32 +60,60 @@ module FlowObject
54
60
  wrap(name, delegate: true, &block)
55
61
  end
56
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
+
57
83
  private
58
84
 
59
85
  def halt_flow?(object, id)
60
- !object.valid?
86
+ false
61
87
  end
62
88
 
63
89
  def __fo_process__(flow: :main)
64
- failure, step_name = false, self.in
65
- plan = __fo_build_flow__(flow, step_name, __fo_wrap_input__)
90
+ failure, step_name, group = false, self.in, :input
91
+ plan = __fo_build_flow__(flow, step_name, group, __fo_wrap_input__)
66
92
  cascade = __fo_run_flow__(plan,
67
93
  proc{|_,id| step_name = id.title},
68
- proc{ failure = true })
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
69
98
  [cascade, step_name, failure]
70
99
  end
71
100
 
72
- def __fo_build_flow__(flow, step_name, object)
73
- public_send(:"build_#{flow}", step_name, object)
101
+ def __fo_build_flow__(flow, step_name, group, object)
102
+ public_send(:"build_#{flow}", title: step_name, group: group, object: object)
74
103
  end
75
104
 
76
- def __fo_run_flow__(plan, on_step, on_failure)
105
+ def __fo_run_flow__(plan, on_step, on_failure, on_input, on_flow)
106
+ step_index = 0
77
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
78
110
  on_step.call(object, id)
111
+ step_index += 1
79
112
  if halt_flow?(object, id)
80
113
  on_failure.call(object, id)
81
114
  throw :halt
82
115
  end
116
+ after_input_check.call(object) if after_input_check && id.group == :input
83
117
  end
84
118
  end
85
119
 
@@ -1,3 +1,3 @@
1
1
  module FlowObject
2
- VERSION = '0.1.5'.freeze
2
+ VERSION = '0.2.0'.freeze
3
3
  end
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.5
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-03-04 00:00:00.000000000 Z
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.12
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.12
26
+ version: 0.2.13
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement