core-pipeline 0.2.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +25 -0
- data/lib/core/pipeline/action.rb +3 -3
- data/lib/core/pipeline/callable.rb +25 -4
- data/lib/core/pipeline/compiler.rb +27 -18
- data/lib/core/pipeline/version.rb +1 -1
- data/lib/is/pipeline/controller.rb +21 -0
- data/lib/is/pipeline.rb +7 -10
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a1893498a0bd9f99c296d22dc1db1cfc66306b73a77a89a30c0829e3958f8954
|
4
|
+
data.tar.gz: 5496c708adb86448f72b3239ff6210dfd6d9a41aa3729e0a7d63e58328a19ace
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2b96487e68c5aff4c901f785b165cb3c11719053d8bb30d742a7982075fdb98164041522d205dcd3eacbe8d1f40794498c7b0a28fcc7a6d28e9a414631dd3eca
|
7
|
+
data.tar.gz: 52e9f1d1ebd353b42fc6d27a55dc867b6b7d3a1975ccab209839d4b39cb51e7ca4eaed3211e30168eb6a91670f9e57dd64ed6e7b6ada62d2ba36efe77cde903e
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,28 @@
|
|
1
|
+
## [v0.5.0](https://github.com/metabahn/corerb/releases/tag/2021-11-06)
|
2
|
+
|
3
|
+
*released on 2021-11-06*
|
4
|
+
|
5
|
+
* `add` [#105](https://github.com/metabahn/corerb/pull/105) Move pipeline control methods to their own module ([bryanp](https://github.com/bryanp))
|
6
|
+
|
7
|
+
## [v0.4.1](https://github.com/metabahn/corerb/releases/tag/2021-11-03)
|
8
|
+
|
9
|
+
*released on 2021-11-03*
|
10
|
+
|
11
|
+
* `fix` [#99](https://github.com/metabahn/corerb/pull/99) Prevent pipelines from being recompiled unnecessarily ([bryanp](https://github.com/bryanp))
|
12
|
+
|
13
|
+
## [v0.4.0](https://github.com/metabahn/corerb/releases/tag/2021-11-02.1)
|
14
|
+
|
15
|
+
*released on 2021-11-02*
|
16
|
+
|
17
|
+
* `add` [#98](https://github.com/metabahn/corerb/pull/98) Add a finalizer to pipelines ([bryanp](https://github.com/bryanp))
|
18
|
+
|
19
|
+
## [v0.3.0](https://github.com/metabahn/corerb/releases/tag/2021-11-02)
|
20
|
+
|
21
|
+
*released on 2021-11-02*
|
22
|
+
|
23
|
+
* `chg` [#97](https://github.com/metabahn/corerb/pull/97) Designate internal state with leading and trailing double underscores ([bryanp](https://github.com/bryanp))
|
24
|
+
* `chg` [#89](https://github.com/metabahn/corerb/pull/89) Allow the pipeline compiler to be extended ([bryanp](https://github.com/bryanp))
|
25
|
+
|
1
26
|
## [v0.2.0](https://github.com/metabahn/corerb/releases/tag/2021-10-24)
|
2
27
|
|
3
28
|
*released on 2021-10-24*
|
data/lib/core/pipeline/action.rb
CHANGED
@@ -10,7 +10,7 @@ module Core
|
|
10
10
|
#
|
11
11
|
class Action
|
12
12
|
include Is::Stateful
|
13
|
-
state :
|
13
|
+
state :__used_random_suffixes__, default: []
|
14
14
|
|
15
15
|
class << self
|
16
16
|
# [public] Builds an action for a given target.
|
@@ -40,10 +40,10 @@ module Core
|
|
40
40
|
|
41
41
|
def build_name
|
42
42
|
suffix = generate_random_suffix
|
43
|
-
if
|
43
|
+
if __used_random_suffixes__.include?(suffix)
|
44
44
|
build_name
|
45
45
|
else
|
46
|
-
|
46
|
+
__used_random_suffixes__ << suffix
|
47
47
|
"action_#{suffix}"
|
48
48
|
end
|
49
49
|
end
|
@@ -19,6 +19,7 @@ module Core
|
|
19
19
|
@actions = []
|
20
20
|
@skipped = []
|
21
21
|
@compiled = false
|
22
|
+
@compiler = Compiler
|
22
23
|
end
|
23
24
|
|
24
25
|
def initialize_copy(...)
|
@@ -30,6 +31,10 @@ module Core
|
|
30
31
|
attr_reader :actions
|
31
32
|
attr_reader :skipped
|
32
33
|
|
34
|
+
# [public]
|
35
|
+
#
|
36
|
+
attr_writer :compiler
|
37
|
+
|
33
38
|
# [public] Relocates to another object context.
|
34
39
|
#
|
35
40
|
def relocate(object)
|
@@ -97,23 +102,39 @@ module Core
|
|
97
102
|
# [public] Calls the pipeline in context of an object with the given arguments.
|
98
103
|
#
|
99
104
|
def call(object, ...)
|
100
|
-
|
105
|
+
finalize.call(object, ...)
|
106
|
+
end
|
107
|
+
|
108
|
+
# [public] Finalizes the pipeline.
|
109
|
+
#
|
110
|
+
def finalize
|
111
|
+
compile
|
112
|
+
|
113
|
+
self
|
101
114
|
end
|
102
115
|
|
103
116
|
private def compile
|
104
|
-
|
117
|
+
return if compiled?
|
118
|
+
|
119
|
+
instance_eval(@compiler.compile(self, @object), __FILE__, __LINE__ - 1)
|
105
120
|
@compiled = true
|
106
|
-
self
|
107
121
|
end
|
108
122
|
|
109
123
|
private def recompile
|
110
|
-
|
124
|
+
remove_compiled_call
|
111
125
|
compile
|
112
126
|
end
|
113
127
|
|
114
128
|
private def compiled?
|
115
129
|
@compiled == true
|
116
130
|
end
|
131
|
+
|
132
|
+
private def remove_compiled_call
|
133
|
+
return unless compiled?
|
134
|
+
|
135
|
+
singleton_class.remove_method(:call)
|
136
|
+
@compiled = false
|
137
|
+
end
|
117
138
|
end
|
118
139
|
end
|
119
140
|
end
|
@@ -21,32 +21,39 @@ module Core
|
|
21
21
|
CODE
|
22
22
|
end
|
23
23
|
|
24
|
+
# [public]
|
25
|
+
#
|
24
26
|
private def compile_call(callable, object)
|
25
27
|
compiled = +""
|
26
|
-
finalized_actions(callable, object).
|
27
|
-
compiled << "begin
|
28
|
+
finalized_actions(callable, object).each_value do |action|
|
29
|
+
compiled << "begin\n"
|
30
|
+
compiled << compile_action(action, object)
|
31
|
+
compiled << "rescue Core::Pipeline::Signals::Rejected\n"
|
32
|
+
compiled << "end\n"
|
33
|
+
end
|
28
34
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
35
|
+
compiled
|
36
|
+
end
|
37
|
+
|
38
|
+
# [public]
|
39
|
+
#
|
40
|
+
private def compile_action(action, object)
|
41
|
+
case action[:finalized]
|
42
|
+
when Symbol
|
43
|
+
if object.private_method_defined?(action[:finalized])
|
44
|
+
"object.send(#{action[:finalized].inspect}, ...)\n"
|
36
45
|
else
|
37
|
-
"
|
46
|
+
"object.#{action[:finalized]}(...)\n"
|
38
47
|
end
|
39
|
-
|
40
|
-
|
48
|
+
else
|
49
|
+
"@__finalized_actions__[#{action[:object_id]}][:finalized].call(...)\n"
|
41
50
|
end
|
42
|
-
|
43
|
-
compiled
|
44
51
|
end
|
45
52
|
|
46
53
|
private def finalized_actions(callable, object)
|
47
54
|
validate_skipped_actions(callable)
|
48
55
|
finalized_actions = build_finalized_actions(callable, object)
|
49
|
-
callable.instance_variable_set(:@
|
56
|
+
callable.instance_variable_set(:@__finalized_actions__, finalized_actions)
|
50
57
|
end
|
51
58
|
|
52
59
|
private def validate_skipped_actions(callable)
|
@@ -63,13 +70,15 @@ module Core
|
|
63
70
|
}.map { |action|
|
64
71
|
finalized = action.finalize(object)
|
65
72
|
|
66
|
-
if action.curried?
|
73
|
+
finalized = if action.curried?
|
67
74
|
wrap_finalized_action_for_context(finalized, action.context || object)
|
68
75
|
else
|
69
76
|
finalized
|
70
77
|
end
|
78
|
+
|
79
|
+
{object: action, finalized: finalized, object_id: finalized.object_id}
|
71
80
|
}.each_with_object({}) { |action, lookup|
|
72
|
-
lookup[action
|
81
|
+
lookup[action[:object_id]] = action
|
73
82
|
}
|
74
83
|
end
|
75
84
|
|
@@ -137,7 +146,7 @@ module Core
|
|
137
146
|
|
138
147
|
code = <<~CODE
|
139
148
|
def #{wrapped_name}(*args, **kwargs, &block)
|
140
|
-
|
149
|
+
self.#{finalized}(#{signature})
|
141
150
|
end
|
142
151
|
CODE
|
143
152
|
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Is
|
4
|
+
module Pipeline
|
5
|
+
# [public]
|
6
|
+
#
|
7
|
+
module Controller
|
8
|
+
# [public] Halts the execution of the pipeline, setting the pipeline's current value to the given object.
|
9
|
+
#
|
10
|
+
private def halt(value = nil)
|
11
|
+
raise Core::Pipeline::Signals::Halted.new(value)
|
12
|
+
end
|
13
|
+
|
14
|
+
# [public] Rejects the current action, skipping the rest of the action and calling remaining pipeline actions.
|
15
|
+
#
|
16
|
+
private def reject
|
17
|
+
raise Core::Pipeline::Signals::Rejected
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/lib/is/pipeline.rb
CHANGED
@@ -3,6 +3,7 @@
|
|
3
3
|
require "is/extension"
|
4
4
|
require "is/stateful"
|
5
5
|
|
6
|
+
require_relative "pipeline/controller"
|
6
7
|
require_relative "../core/pipeline/callable"
|
7
8
|
require_relative "../core/pipeline/compiler"
|
8
9
|
require_relative "../core/pipeline/signals/halted"
|
@@ -56,7 +57,7 @@ module Is
|
|
56
57
|
end
|
57
58
|
end
|
58
59
|
|
59
|
-
extends :implementation do
|
60
|
+
extends :implementation, dependencies: [Is::Pipeline::Controller] do
|
60
61
|
# [public] Calls a pipeline with arguments.
|
61
62
|
#
|
62
63
|
def call(...)
|
@@ -100,16 +101,12 @@ module Is
|
|
100
101
|
end
|
101
102
|
|
102
103
|
extends :implementation, prepend: true do
|
103
|
-
# [public]
|
104
|
+
# [public]
|
104
105
|
#
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
# [public] Rejects the current action, skipping the rest of the action and calling remaining pipeline actions.
|
110
|
-
#
|
111
|
-
private def reject
|
112
|
-
raise Core::Pipeline::Signals::Rejected
|
106
|
+
def finalize
|
107
|
+
super if defined?(super)
|
108
|
+
pipeline.finalize
|
109
|
+
self
|
113
110
|
end
|
114
111
|
end
|
115
112
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: core-pipeline
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bryan Powell
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-11-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: core-extension
|
@@ -70,6 +70,7 @@ files:
|
|
70
70
|
- lib/core/pipeline/signals/rejected.rb
|
71
71
|
- lib/core/pipeline/version.rb
|
72
72
|
- lib/is/pipeline.rb
|
73
|
+
- lib/is/pipeline/controller.rb
|
73
74
|
homepage: https://github.com/metabahn/corerb/
|
74
75
|
licenses:
|
75
76
|
- MPL-2.0
|