core-pipeline 0.2.0 → 0.3.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
  SHA256:
3
- metadata.gz: 8a6b3ef16c4e8c95532c84fbcfeffa10e3d8b17b710f8a829ea0ea3735039195
4
- data.tar.gz: e29f64c2b55dda1e75d022c4cca2f6a2c80fe00e13760ea678335abf74b57da4
3
+ metadata.gz: 53ee7741ae5354263c5f7d426eb7ad9b500c01bb4a1ee4c665ce11d054819cea
4
+ data.tar.gz: 8c7e495b2681c54b59e38cc066987e0f52e3ba8a5673f8285c821a38eea98e9d
5
5
  SHA512:
6
- metadata.gz: ccb44ec883364a2a633407dc257f44958386b817210278545e9b0291067437e553c6470616e53bab83876d04db2cebe0100ad727971a68aa955ebff7c3a87f9b
7
- data.tar.gz: 6c1bb9fb0905caf54a3aef8b33bb224bc23779a66d66353b48345f61fe8a8e27c54653c65cf0d563f8073e387263675e9afe4ba0245bcfc9cf03fd8465a6b22b
6
+ metadata.gz: 757e21b99dbb927b0d75f4dbd8f036e3235a982aa9a449260bcb4e4ff09f3a20afb788c3ddcd213d2a75d5b44e105f69bf512a6515991cc97282e584e4a617f7
7
+ data.tar.gz: 241b54f107db94c7fa5afeb1a075d2df1b3cd92c97bc54c9cb3935c283d6b2085d67eb1aeb85d2cb724b0cc6785f3bacb64062233ab50c5150f44bfd70603636
data/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ ## [v0.3.0](https://github.com/metabahn/corerb/releases/tag/2021-11-02)
2
+
3
+ *released on 2021-11-02*
4
+
5
+ * `chg` [#97](https://github.com/metabahn/corerb/pull/97) Designate internal state with leading and trailing double underscores ([bryanp](https://github.com/bryanp))
6
+ * `chg` [#89](https://github.com/metabahn/corerb/pull/89) Allow the pipeline compiler to be extended ([bryanp](https://github.com/bryanp))
7
+
1
8
  ## [v0.2.0](https://github.com/metabahn/corerb/releases/tag/2021-10-24)
2
9
 
3
10
  *released on 2021-10-24*
@@ -10,7 +10,7 @@ module Core
10
10
  #
11
11
  class Action
12
12
  include Is::Stateful
13
- state :__used_random_suffixes, default: []
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 __used_random_suffixes.include?(suffix)
43
+ if __used_random_suffixes__.include?(suffix)
44
44
  build_name
45
45
  else
46
- __used_random_suffixes << suffix
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)
@@ -101,7 +106,7 @@ module Core
101
106
  end
102
107
 
103
108
  private def compile
104
- instance_eval(Compiler.compile(self, @object), __FILE__, __LINE__ - 1)
109
+ instance_eval(@compiler.compile(self, @object), __FILE__, __LINE__ - 1)
105
110
  @compiled = true
106
111
  self
107
112
  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).each_pair do |object_id, action|
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
- compiled << case action
30
- when Symbol
31
- if object.private_method_defined?(action)
32
- "object.send(#{action.inspect}, ...); "
33
- else
34
- "object.#{action}(...); "
35
- end
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
- "@__finalized_actions[#{object_id}].call(...); "
46
+ "object.#{action[:finalized]}(...)\n"
38
47
  end
39
-
40
- compiled << "rescue Core::Pipeline::Signals::Rejected; end\n"
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(:@__finalized_actions, finalized_actions)
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.object_id] = 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
- #{finalized}(#{signature})
149
+ self.#{finalized}(#{signature})
141
150
  end
142
151
  CODE
143
152
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Core
4
4
  module Pipeline
5
- VERSION = "0.2.0"
5
+ VERSION = "0.3.0"
6
6
 
7
7
  def self.version
8
8
  VERSION
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.2.0
4
+ version: 0.3.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-10-24 00:00:00.000000000 Z
11
+ date: 2021-11-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: core-extension