callable_tree 0.1.3 → 0.2.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 +7 -0
- data/Gemfile.lock +1 -1
- data/README.md +2 -2
- data/callable_tree.gemspec +1 -1
- data/lib/callable_tree/node/external.rb +13 -0
- data/lib/callable_tree/node/internal.rb +19 -12
- data/lib/callable_tree/version.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9213a2a82a38c85e401f291bf2d37e60210bf167c765576033eed93fb1d7cbbd
|
4
|
+
data.tar.gz: 4a3f2fce73c82b8e5b7e537d21eeedc500e84dbe9f3c972c596701b654a9f234
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 72ccbffb1ffe2e66ddf41b2f29c715c9cda1d6a91dc8ee5ef493bcaa531b2c1c99ee9024b1776a8c9ecad6e82b84b051d0121c55e9abc26a1ba3d4bb449dced2
|
7
|
+
data.tar.gz: 243f05208c10de0a60af884479f8a2a9d3edc5735b16fece2994b694d0734bf75f57f1dfc57afc8c265df038fe736fd86e063042362d495140410819f47bbc70
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,12 @@
|
|
1
1
|
## [Unreleased]
|
2
2
|
|
3
|
+
## [0.2.0] - 2021-06-15
|
4
|
+
- Change `CallableTree::Node::Internal#append` to return a new instance.
|
5
|
+
To keep the same behavior as the older version, use `CallableTree::Node::External#append!` that make destructive change.
|
6
|
+
- Remove `CallableTree::Node::Internal#<<`. Use `CallableTree::Node::External#append!` instead.
|
7
|
+
- Change `CallableTree::Node::External#verbosify` to return a new instance.
|
8
|
+
To keep the same behavior as the older version, use `CallableTree::Node::External#verbosify!` that make destructive change.
|
9
|
+
|
3
10
|
## [0.1.3] - 2021-06-12
|
4
11
|
- Minor improvements
|
5
12
|
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -158,7 +158,7 @@ Run `examples/internal-seek.rb`:
|
|
158
158
|
---
|
159
159
|
```
|
160
160
|
|
161
|
-
#### `CallableTree::Node::Internal#broadcast`
|
161
|
+
#### `CallableTree::Node::Internal#broadcast`
|
162
162
|
|
163
163
|
This strategy calls all child nodes of the internal node and ignores their `terminate?` methods, and then outputs their results as array.
|
164
164
|
|
@@ -212,7 +212,7 @@ Run `examples/internal-broadcast.rb`:
|
|
212
212
|
10 -> [nil, nil]
|
213
213
|
```
|
214
214
|
|
215
|
-
#### `CallableTree::Node::Internal#compose`
|
215
|
+
#### `CallableTree::Node::Internal#compose`
|
216
216
|
|
217
217
|
This strategy calls all child nodes of the internal node in order to input the output of the previous node to the next node and ignores their `terminate?` methods, and then outputs a single result.
|
218
218
|
|
data/callable_tree.gemspec
CHANGED
@@ -9,7 +9,7 @@ Gem::Specification.new do |spec|
|
|
9
9
|
spec.email = ['jsmmr@icloud.com']
|
10
10
|
|
11
11
|
spec.summary = 'Builds a tree by linking callable nodes. The nodes that match the conditions are called in a chain from the root node to the leaf node. These are like nested `if` or `case` expressions.'
|
12
|
-
spec.description = 'Builds a tree by linking callable nodes. The nodes that match the
|
12
|
+
spec.description = 'Builds a tree by linking callable nodes. The nodes that match the conditions are called in a chain from the root node to the leaf node. These are like nested `if` or `case` expressions.'
|
13
13
|
spec.homepage = 'https://github.com/jsmmr/ruby_callable_tree'
|
14
14
|
spec.license = 'MIT'
|
15
15
|
spec.required_ruby_version = Gem::Requirement.new('>= 2.4.0')
|
@@ -18,6 +18,12 @@ module CallableTree
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def verbosify
|
21
|
+
clone.tap do |node|
|
22
|
+
node.extend Verbose
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def verbosify!
|
21
27
|
extend Verbose
|
22
28
|
self
|
23
29
|
end
|
@@ -31,6 +37,13 @@ module CallableTree
|
|
31
37
|
.class
|
32
38
|
end
|
33
39
|
|
40
|
+
private
|
41
|
+
|
42
|
+
def initialize_copy(_node)
|
43
|
+
super
|
44
|
+
send(:parent=, nil)
|
45
|
+
end
|
46
|
+
|
34
47
|
class Proxy
|
35
48
|
extend ::Forwardable
|
36
49
|
include External
|
@@ -9,20 +9,17 @@ module CallableTree
|
|
9
9
|
@children ||= []
|
10
10
|
end
|
11
11
|
|
12
|
-
def
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
else
|
17
|
-
External.proxify(callable)
|
18
|
-
end
|
19
|
-
.tap { |node| node.send(:parent=, self) }
|
20
|
-
|
21
|
-
self
|
12
|
+
def append(*callables)
|
13
|
+
clone.tap do |node|
|
14
|
+
node.append!(*callables)
|
15
|
+
end
|
22
16
|
end
|
23
17
|
|
24
|
-
def append(*callables)
|
25
|
-
callables
|
18
|
+
def append!(*callables)
|
19
|
+
callables
|
20
|
+
.map { |callable| nodeify(callable) }
|
21
|
+
.tap { |nodes| children.push(*nodes) } # Use Array#push for Ruby 2.4
|
22
|
+
|
26
23
|
self
|
27
24
|
end
|
28
25
|
|
@@ -68,12 +65,22 @@ module CallableTree
|
|
68
65
|
|
69
66
|
attr_writer :children, :strategy
|
70
67
|
|
68
|
+
def nodeify(callable)
|
69
|
+
if callable.is_a?(Node)
|
70
|
+
callable.clone
|
71
|
+
else
|
72
|
+
External.proxify(callable)
|
73
|
+
end
|
74
|
+
.tap { |node| node.send(:parent=, self) }
|
75
|
+
end
|
76
|
+
|
71
77
|
def strategy
|
72
78
|
@strategy ||= Seek.new
|
73
79
|
end
|
74
80
|
|
75
81
|
def initialize_copy(_node)
|
76
82
|
super
|
83
|
+
send(:parent=, nil)
|
77
84
|
self.children = children.map do |node|
|
78
85
|
node.clone.tap { |new_node| new_node.send(:parent=, self) }
|
79
86
|
end
|
metadata
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: callable_tree
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- jsmmr
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-06-
|
11
|
+
date: 2021-06-14 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
|
-
description: Builds a tree by linking callable nodes. The nodes that match the
|
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
|
15
15
|
`if` or `case` expressions.
|
16
16
|
email:
|
@@ -60,7 +60,7 @@ licenses:
|
|
60
60
|
metadata:
|
61
61
|
homepage_uri: https://github.com/jsmmr/ruby_callable_tree
|
62
62
|
source_code_uri: https://github.com/jsmmr/ruby_callable_tree
|
63
|
-
changelog_uri: https://github.com/jsmmr/ruby_callable_tree/blob/v0.
|
63
|
+
changelog_uri: https://github.com/jsmmr/ruby_callable_tree/blob/v0.2.0/CHANGELOG.md
|
64
64
|
post_install_message:
|
65
65
|
rdoc_options: []
|
66
66
|
require_paths:
|