callable_tree 0.3.6 → 0.3.7

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: 2a83d353d4049c06aa0a0d5f18f56c5c6d0d909cd4a54f6bbcba7faf4e835c0f
4
- data.tar.gz: ab803f4e8b613a0ceb5e4d3ca21d38e1a5cf2a238db61384c0ec85b437fd7d73
3
+ metadata.gz: 0ebaae495d65a776fa0eea8c4aa5e23a1dca39245f05531b1d79bb7384c27228
4
+ data.tar.gz: af843950714bc7302b3fab17fc23a775e5f436f97923aad80783998794d110ab
5
5
  SHA512:
6
- metadata.gz: 27dd59b36d4ebc99395df901a900d72510928f5f4a9603405b83f54d0566652fda2253bcda7bf6efee1ad0363919c5ec7bb63a1ec1e0efc488e656d6ff1bce3a
7
- data.tar.gz: 3029f92901053688715cffce367d0e44f01402743413dfd38dc52c6c63221094fe2d3774cf2b1b98d66b84dd6837c8d6e6430c228ce3f196e60f9222286a3a56
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.6)
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.0)
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)
@@ -90,7 +90,7 @@ loggable = proc do |node|
90
90
  matched
91
91
  end
92
92
 
93
- if node.is_a?(CallableTree::Node::External)
93
+ if node.external?
94
94
  input_label = 'Input :'
95
95
  output_label = 'Output:'
96
96
 
@@ -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
@@ -12,6 +12,7 @@ module CallableTree
12
12
 
13
13
  def call(*inputs, **options)
14
14
  output = super(*inputs, **options)
15
+ options.delete(:_node_)
15
16
  routes = self.routes
16
17
 
17
18
  Output.new(output, options, routes)
@@ -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.is_a?(Internal) }
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.is_a?(Internal)
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.is_a?(Internal) && node.shake!(&block).child_nodes.empty?
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
@@ -46,6 +46,14 @@ module CallableTree
46
46
  !output.nil?
47
47
  end
48
48
 
49
+ def internal?
50
+ raise ::CallableTree::Error, 'Not implemented'
51
+ end
52
+
53
+ def external?
54
+ raise ::CallableTree::Error, 'Not implemented'
55
+ end
56
+
49
57
  protected
50
58
 
51
59
  attr_writer :parent
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module CallableTree
4
- VERSION = '0.3.6'
4
+ VERSION = '0.3.7'
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.6
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-03-29 00:00:00.000000000 Z
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.6/CHANGELOG.md
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: