callable_tree 0.3.6 → 0.3.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/Gemfile.lock +2 -2
- data/examples/builder/logging.rb +1 -1
- data/lib/callable_tree/node/builder.rb +3 -3
- data/lib/callable_tree/node/external/verbose.rb +1 -0
- data/lib/callable_tree/node/external.rb +15 -0
- data/lib/callable_tree/node/internal.rb +18 -3
- data/lib/callable_tree/node.rb +8 -0
- data/lib/callable_tree/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0ebaae495d65a776fa0eea8c4aa5e23a1dca39245f05531b1d79bb7384c27228
|
4
|
+
data.tar.gz: af843950714bc7302b3fab17fc23a775e5f436f97923aad80783998794d110ab
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5311c4a2ad2436815362a8349e278b73c8c568a4bf4721c990d7a5b5c8c74d876267dc5729c67f0e6e9a4c540e99cffa3d9ece8b9046acf057ca2f48e20a97ab
|
7
|
+
data.tar.gz: baa36b79d0ad3ba777fcad27c8b04c7ff1b1da7d665c1f74dbadf49e6d36828ed0fc3d0eaa1cc45c54107e24806a8ec66e4b719095e055260fec8a3ec16669c2
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,11 @@
|
|
1
1
|
## [Unreleased]
|
2
2
|
|
3
|
+
## [0.3.7] - 2022-04-09
|
4
|
+
|
5
|
+
- Add `CallableTree::Node#internal?`
|
6
|
+
- Add `CallableTree::Node#external?`
|
7
|
+
- (Experimental) Change the callables (matcher, caller, terminator) specified in the builder style to receive the current node instance as the `_node_` keyword argument.
|
8
|
+
|
3
9
|
## [0.3.6] - 2022-03-29
|
4
10
|
|
5
11
|
- (Experimental) Add `CallableTree::Node::Hooks::Matcher`.
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
callable_tree (0.3.
|
4
|
+
callable_tree (0.3.7)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
@@ -17,7 +17,7 @@ GEM
|
|
17
17
|
rspec-expectations (3.11.0)
|
18
18
|
diff-lcs (>= 1.2.0, < 2.0)
|
19
19
|
rspec-support (~> 3.11.0)
|
20
|
-
rspec-mocks (3.11.
|
20
|
+
rspec-mocks (3.11.1)
|
21
21
|
diff-lcs (>= 1.2.0, < 2.0)
|
22
22
|
rspec-support (~> 3.11.0)
|
23
23
|
rspec-support (3.11.0)
|
data/examples/builder/logging.rb
CHANGED
@@ -51,7 +51,7 @@ module CallableTree
|
|
51
51
|
|
52
52
|
if matcher
|
53
53
|
define_method(:match?) do |*inputs, **options|
|
54
|
-
matcher.call(*inputs, **options) do |*inputs, **options|
|
54
|
+
matcher.call(*inputs, **options, _node_: self) do |*inputs, **options|
|
55
55
|
super(*inputs, **options)
|
56
56
|
end
|
57
57
|
end
|
@@ -59,7 +59,7 @@ module CallableTree
|
|
59
59
|
|
60
60
|
if caller
|
61
61
|
define_method(:call) do |*inputs, **options|
|
62
|
-
caller.call(*inputs, **options) do |*inputs, **options|
|
62
|
+
caller.call(*inputs, **options, _node_: self) do |*inputs, **options|
|
63
63
|
super(*inputs, **options)
|
64
64
|
end
|
65
65
|
end
|
@@ -67,7 +67,7 @@ module CallableTree
|
|
67
67
|
|
68
68
|
if terminator
|
69
69
|
define_method(:terminate?) do |output, *inputs, **options|
|
70
|
-
terminator.call(output, *inputs, **options) do |output, *inputs, **options|
|
70
|
+
terminator.call(output, *inputs, **options, _node_: self) do |output, *inputs, **options|
|
71
71
|
super(output, *inputs, **options)
|
72
72
|
end
|
73
73
|
end
|
@@ -5,6 +5,13 @@ module CallableTree
|
|
5
5
|
module External
|
6
6
|
include Node
|
7
7
|
|
8
|
+
def self.included(mod)
|
9
|
+
if mod.include?(Internal)
|
10
|
+
raise ::CallableTree::Error,
|
11
|
+
"#{mod} cannot include #{self} together with #{Internal}"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
8
15
|
def self.proxify(callable)
|
9
16
|
Proxy.new(callable)
|
10
17
|
end
|
@@ -41,6 +48,14 @@ module CallableTree
|
|
41
48
|
{ identity => nil }
|
42
49
|
end
|
43
50
|
|
51
|
+
def internal?
|
52
|
+
false
|
53
|
+
end
|
54
|
+
|
55
|
+
def external?
|
56
|
+
true
|
57
|
+
end
|
58
|
+
|
44
59
|
private
|
45
60
|
|
46
61
|
def initialize_copy(_node)
|
@@ -6,6 +6,13 @@ module CallableTree
|
|
6
6
|
extend ::Forwardable
|
7
7
|
include Node
|
8
8
|
|
9
|
+
def self.included(mod)
|
10
|
+
if mod.include?(External)
|
11
|
+
raise ::CallableTree::Error,
|
12
|
+
"#{mod} cannot include #{self} together with #{External}"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
9
16
|
def_delegators :child_nodes, :[], :at
|
10
17
|
|
11
18
|
def children
|
@@ -35,7 +42,7 @@ module CallableTree
|
|
35
42
|
if recursive
|
36
43
|
child_nodes
|
37
44
|
.lazy
|
38
|
-
.select { |node| node.
|
45
|
+
.select { |node| node.internal? }
|
39
46
|
.map { |node| node.find(recursive: true, &block) }
|
40
47
|
.reject(&:nil?)
|
41
48
|
.first
|
@@ -51,7 +58,7 @@ module CallableTree
|
|
51
58
|
|
52
59
|
if recursive
|
53
60
|
child_nodes.each do |node|
|
54
|
-
node.reject!(recursive: true, &block) if node.
|
61
|
+
node.reject!(recursive: true, &block) if node.internal?
|
55
62
|
end
|
56
63
|
end
|
57
64
|
|
@@ -66,7 +73,7 @@ module CallableTree
|
|
66
73
|
reject!(&block) if block_given?
|
67
74
|
|
68
75
|
reject! do |node|
|
69
|
-
node.
|
76
|
+
node.internal? && node.shake!(&block).child_nodes.empty?
|
70
77
|
end
|
71
78
|
end
|
72
79
|
|
@@ -156,6 +163,14 @@ module CallableTree
|
|
156
163
|
{ key => value }
|
157
164
|
end
|
158
165
|
|
166
|
+
def internal?
|
167
|
+
true
|
168
|
+
end
|
169
|
+
|
170
|
+
def external?
|
171
|
+
false
|
172
|
+
end
|
173
|
+
|
159
174
|
protected
|
160
175
|
|
161
176
|
attr_writer :strategy
|
data/lib/callable_tree/node.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: callable_tree
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- jsmmr
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-04-09 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Builds a tree by linking callable nodes. The nodes that match the conditions
|
14
14
|
are called in a chain from the root node to the leaf node. These are like nested
|
@@ -71,7 +71,7 @@ licenses:
|
|
71
71
|
metadata:
|
72
72
|
homepage_uri: https://github.com/jsmmr/ruby_callable_tree
|
73
73
|
source_code_uri: https://github.com/jsmmr/ruby_callable_tree
|
74
|
-
changelog_uri: https://github.com/jsmmr/ruby_callable_tree/blob/v0.3.
|
74
|
+
changelog_uri: https://github.com/jsmmr/ruby_callable_tree/blob/v0.3.7/CHANGELOG.md
|
75
75
|
post_install_message:
|
76
76
|
rdoc_options: []
|
77
77
|
require_paths:
|