callable_tree 0.3.3 → 0.3.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/build.yml +1 -1
- data/.ruby-version +1 -1
- data/CHANGELOG.md +26 -0
- data/Gemfile.lock +3 -4
- data/README.md +47 -47
- data/examples/builder/hooks-caller.rb +38 -0
- data/examples/builder/internal-broadcastable.rb +72 -0
- data/examples/builder/internal-composable.rb +72 -0
- data/examples/builder/internal-seekable.rb +93 -0
- data/examples/builder/logging.rb +126 -0
- data/examples/{hooks-call.rb → hooks-caller.rb} +8 -8
- data/examples/{internal-broadcast.rb → internal-broadcastable.rb} +6 -6
- data/examples/{internal-compose.rb → internal-composable.rb} +6 -6
- data/examples/{internal-seek.rb → internal-seekable.rb} +3 -3
- data/lib/callable_tree/node/builder.rb +85 -0
- data/lib/callable_tree/node/external/builder.rb +23 -0
- data/lib/callable_tree/node/external/verbose.rb +0 -1
- data/lib/callable_tree/node/hooks/caller.rb +110 -0
- data/lib/callable_tree/node/hooks/matcher.rb +101 -0
- data/lib/callable_tree/node/internal/builder.rb +21 -0
- data/lib/callable_tree/node/internal.rb +12 -0
- data/lib/callable_tree/node/root.rb +2 -1
- data/lib/callable_tree/version.rb +1 -1
- data/lib/callable_tree.rb +5 -1
- metadata +18 -9
- data/lib/callable_tree/node/hooks/call.rb +0 -81
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.6
|
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-03-29 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
|
@@ -33,23 +33,32 @@ files:
|
|
33
33
|
- bin/console
|
34
34
|
- bin/setup
|
35
35
|
- callable_tree.gemspec
|
36
|
+
- examples/builder/hooks-caller.rb
|
37
|
+
- examples/builder/internal-broadcastable.rb
|
38
|
+
- examples/builder/internal-composable.rb
|
39
|
+
- examples/builder/internal-seekable.rb
|
40
|
+
- examples/builder/logging.rb
|
36
41
|
- examples/docs/animals.json
|
37
42
|
- examples/docs/animals.xml
|
38
43
|
- examples/docs/fruits.json
|
39
44
|
- examples/docs/fruits.xml
|
40
45
|
- examples/external-verbosify.rb
|
41
|
-
- examples/hooks-
|
46
|
+
- examples/hooks-caller.rb
|
42
47
|
- examples/identity.rb
|
43
|
-
- examples/internal-
|
44
|
-
- examples/internal-
|
45
|
-
- examples/internal-
|
48
|
+
- examples/internal-broadcastable.rb
|
49
|
+
- examples/internal-composable.rb
|
50
|
+
- examples/internal-seekable.rb
|
46
51
|
- examples/logging.rb
|
47
52
|
- lib/callable_tree.rb
|
48
53
|
- lib/callable_tree/node.rb
|
54
|
+
- lib/callable_tree/node/builder.rb
|
49
55
|
- lib/callable_tree/node/external.rb
|
56
|
+
- lib/callable_tree/node/external/builder.rb
|
50
57
|
- lib/callable_tree/node/external/verbose.rb
|
51
|
-
- lib/callable_tree/node/hooks/
|
58
|
+
- lib/callable_tree/node/hooks/caller.rb
|
59
|
+
- lib/callable_tree/node/hooks/matcher.rb
|
52
60
|
- lib/callable_tree/node/internal.rb
|
61
|
+
- lib/callable_tree/node/internal/builder.rb
|
53
62
|
- lib/callable_tree/node/internal/strategy.rb
|
54
63
|
- lib/callable_tree/node/internal/strategy/broadcast.rb
|
55
64
|
- lib/callable_tree/node/internal/strategy/compose.rb
|
@@ -62,7 +71,7 @@ licenses:
|
|
62
71
|
metadata:
|
63
72
|
homepage_uri: https://github.com/jsmmr/ruby_callable_tree
|
64
73
|
source_code_uri: https://github.com/jsmmr/ruby_callable_tree
|
65
|
-
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.6/CHANGELOG.md
|
66
75
|
post_install_message:
|
67
76
|
rdoc_options: []
|
68
77
|
require_paths:
|
@@ -78,7 +87,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
78
87
|
- !ruby/object:Gem::Version
|
79
88
|
version: '0'
|
80
89
|
requirements: []
|
81
|
-
rubygems_version: 3.3.
|
90
|
+
rubygems_version: 3.3.7
|
82
91
|
signing_key:
|
83
92
|
specification_version: 4
|
84
93
|
summary: Builds a tree by linking callable nodes. The nodes that match the conditions
|
@@ -1,81 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module CallableTree
|
4
|
-
module Node
|
5
|
-
module Hooks
|
6
|
-
module Call
|
7
|
-
def self.included(_subclass)
|
8
|
-
raise ::CallableTree::Error, "#{self} must be prepended"
|
9
|
-
end
|
10
|
-
|
11
|
-
def before_call(&block)
|
12
|
-
clone.before_call!(&block)
|
13
|
-
end
|
14
|
-
|
15
|
-
def before_call!(&block)
|
16
|
-
before_callbacks << block
|
17
|
-
self
|
18
|
-
end
|
19
|
-
|
20
|
-
def around_call(&block)
|
21
|
-
clone.around_call!(&block)
|
22
|
-
end
|
23
|
-
|
24
|
-
def around_call!(&block)
|
25
|
-
around_callbacks << block
|
26
|
-
self
|
27
|
-
end
|
28
|
-
|
29
|
-
def after_call(&block)
|
30
|
-
clone.after_call!(&block)
|
31
|
-
end
|
32
|
-
|
33
|
-
def after_call!(&block)
|
34
|
-
after_callbacks << block
|
35
|
-
self
|
36
|
-
end
|
37
|
-
|
38
|
-
def call(*inputs, **options)
|
39
|
-
input_head, *input_tail = inputs
|
40
|
-
|
41
|
-
input_head = before_callbacks.reduce(input_head) do |input_head, callable|
|
42
|
-
callable.call(input_head, *input_tail, self, **options)
|
43
|
-
end
|
44
|
-
|
45
|
-
output = super(input_head, *input_tail, **options)
|
46
|
-
|
47
|
-
output = around_callbacks.reduce(output) do |output, callable|
|
48
|
-
callable.call(input_head, *input_tail, self, **options) { output }
|
49
|
-
end
|
50
|
-
|
51
|
-
after_callbacks.reduce(output) do |output, callable|
|
52
|
-
callable.call(output, self, **options)
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
def before_callbacks
|
57
|
-
@before_callbacks ||= []
|
58
|
-
end
|
59
|
-
|
60
|
-
def around_callbacks
|
61
|
-
@around_callbacks ||= []
|
62
|
-
end
|
63
|
-
|
64
|
-
def after_callbacks
|
65
|
-
@after_callbacks ||= []
|
66
|
-
end
|
67
|
-
|
68
|
-
private
|
69
|
-
|
70
|
-
attr_writer :before_callbacks, :around_callbacks, :after_callbacks
|
71
|
-
|
72
|
-
def initialize_copy(_node)
|
73
|
-
super
|
74
|
-
self.before_callbacks = before_callbacks.map(&:itself)
|
75
|
-
self.around_callbacks = around_callbacks.map(&:itself)
|
76
|
-
self.after_callbacks = after_callbacks.map(&:itself)
|
77
|
-
end
|
78
|
-
end
|
79
|
-
end
|
80
|
-
end
|
81
|
-
end
|