callable_tree 0.3.2 → 0.3.3

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: 5a506dec2678a69b014cff69b6cc4fd94e22b1f7f5027e9230727720c8dc049e
4
- data.tar.gz: 3b7ee0419139ef24f40f8b0714cbd19551568967d0170a4b550a84f528811da4
3
+ metadata.gz: 3feea9db6a3844729a1644e56d60cc0cf8961e95e5ae5d58fcf4eb10eab6c80d
4
+ data.tar.gz: 6de275fcb284556be10c22cea0e310adecadebab11bd5b884b736b809543120c
5
5
  SHA512:
6
- metadata.gz: b84af5f3ae12941eabdb1cdbc159d9a3f424388bffab74c2704d5507a875c924ae637b2b868194244d2530bcbd8bf5895118e42f7a79c91f901854896d686eb5
7
- data.tar.gz: 816f558c0118c57bda18c3b69fef45240c9de5e87a1acea0bcf1f9448e0c67e34a7de613292796635f8e5c16d1835c2ba4bdef959939c44a6358bce94197a82a
6
+ metadata.gz: 14883eaed6a4655f62908ae53dabadd007e56befb50cb8d5b02790d91441afe3749ecf00019709a5ba39b8bfaafeaa8e475a318e62d1a93f21511ef3611d4238
7
+ data.tar.gz: b58152e34c1e7b7c3f9941715d7f512f71d40b1abbacbb7481e965ceb34969117c56b4a9ee218ed62f087dedc7d85ffdde1d9f43ab6beb25aa6da8b89b9dfde1
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.3.3] - 2022-02-19
4
+
5
+ - Add `recursive` option to `CallableTree::Node::Internal#reject` and `CallableTree::Node::Internal#reject!`.
6
+ - Add `CallableTree::Node::Internal#find` to return the first node evaluated as `true` by block.
7
+
3
8
  ## [0.3.2] - 2022-02-05
4
9
 
5
10
  - Change `CallableTree::Node::Hooks::Call#before_call` to return a new instance.
data/Gemfile.lock CHANGED
@@ -1,26 +1,26 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- callable_tree (0.3.2)
4
+ callable_tree (0.3.3)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
9
  diff-lcs (1.5.0)
10
10
  rake (13.0.6)
11
- rspec (3.10.0)
12
- rspec-core (~> 3.10.0)
13
- rspec-expectations (~> 3.10.0)
14
- rspec-mocks (~> 3.10.0)
15
- rspec-core (3.10.2)
16
- rspec-support (~> 3.10.0)
17
- rspec-expectations (3.10.2)
11
+ rspec (3.11.0)
12
+ rspec-core (~> 3.11.0)
13
+ rspec-expectations (~> 3.11.0)
14
+ rspec-mocks (~> 3.11.0)
15
+ rspec-core (3.11.0)
16
+ rspec-support (~> 3.11.0)
17
+ rspec-expectations (3.11.0)
18
18
  diff-lcs (>= 1.2.0, < 2.0)
19
- rspec-support (~> 3.10.0)
20
- rspec-mocks (3.10.3)
19
+ rspec-support (~> 3.11.0)
20
+ rspec-mocks (3.11.0)
21
21
  diff-lcs (>= 1.2.0, < 2.0)
22
- rspec-support (~> 3.10.0)
23
- rspec-support (3.10.3)
22
+ rspec-support (~> 3.11.0)
23
+ rspec-support (3.11.0)
24
24
 
25
25
  PLATFORMS
26
26
  x86_64-darwin-19
@@ -17,9 +17,7 @@ module CallableTree
17
17
  end
18
18
 
19
19
  def append(*callables)
20
- clone.tap do |node|
21
- node.append!(*callables)
22
- end
20
+ clone.append!(*callables)
23
21
  end
24
22
 
25
23
  def append!(*callables)
@@ -30,21 +28,38 @@ module CallableTree
30
28
  self
31
29
  end
32
30
 
33
- def reject(&block)
34
- clone.tap do |node|
35
- node.reject!(&block)
31
+ def find(recursive: false, &block)
32
+ node = child_nodes.find(&block)
33
+ return node if node
34
+
35
+ if recursive
36
+ child_nodes
37
+ .lazy
38
+ .select { |node| node.is_a?(Internal) }
39
+ .map { |node| node.find(recursive: true, &block) }
40
+ .reject(&:nil?)
41
+ .first
36
42
  end
37
43
  end
38
44
 
39
- def reject!(&block)
45
+ def reject(recursive: false, &block)
46
+ clone.reject!(recursive: recursive, &block)
47
+ end
48
+
49
+ def reject!(recursive: false, &block)
40
50
  child_nodes.reject!(&block)
51
+
52
+ if recursive
53
+ child_nodes.each do |node|
54
+ node.reject!(recursive: true, &block) if node.is_a?(Internal)
55
+ end
56
+ end
57
+
41
58
  self
42
59
  end
43
60
 
44
61
  def shake(&block)
45
- clone.tap do |node|
46
- node.shake!(&block)
47
- end
62
+ clone.shake!(&block)
48
63
  end
49
64
 
50
65
  def shake!(&block)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module CallableTree
4
- VERSION = '0.3.2'
4
+ VERSION = '0.3.3'
5
5
  end
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.2
4
+ version: 0.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - jsmmr
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-02-05 00:00:00.000000000 Z
11
+ date: 2022-02-19 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
@@ -62,7 +62,7 @@ licenses:
62
62
  metadata:
63
63
  homepage_uri: https://github.com/jsmmr/ruby_callable_tree
64
64
  source_code_uri: https://github.com/jsmmr/ruby_callable_tree
65
- changelog_uri: https://github.com/jsmmr/ruby_callable_tree/blob/v0.3.2/CHANGELOG.md
65
+ changelog_uri: https://github.com/jsmmr/ruby_callable_tree/blob/v0.3.3/CHANGELOG.md
66
66
  post_install_message:
67
67
  rdoc_options: []
68
68
  require_paths: