callable_tree 0.3.7 → 0.3.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/dependabot.yml +7 -0
- data/.github/workflows/build.yml +3 -5
- data/.github/workflows/codeql-analysis.yml +4 -4
- data/.rubocop.yml +6 -0
- data/.ruby-version +1 -1
- data/CHANGELOG.md +12 -0
- data/Gemfile.lock +3 -3
- data/README.md +460 -276
- data/callable_tree.gemspec +1 -0
- data/examples/builder/external-verbosify.rb +87 -0
- data/examples/builder/hooks.rb +67 -0
- data/examples/builder/identity.rb +91 -0
- data/examples/builder/internal-broadcastable.rb +11 -11
- data/examples/builder/internal-composable.rb +11 -11
- data/examples/builder/internal-seekable.rb +9 -15
- data/examples/builder/logging.rb +36 -39
- data/examples/{external-verbosify.rb → class/external-verbosify.rb} +3 -5
- data/examples/class/hooks.rb +70 -0
- data/examples/{identity.rb → class/identity.rb} +3 -5
- data/examples/{internal-broadcastable.rb → class/internal-broadcastable.rb} +0 -0
- data/examples/{internal-composable.rb → class/internal-composable.rb} +0 -0
- data/examples/{internal-seekable.rb → class/internal-seekable.rb} +3 -5
- data/examples/{logging.rb → class/logging.rb} +47 -47
- data/lib/callable_tree/node/builder.rb +13 -0
- data/lib/callable_tree/node/hooks/terminator.rb +99 -0
- data/lib/callable_tree/node/internal/strategy/broadcast.rb +19 -2
- data/lib/callable_tree/node/internal/strategy/compose.rb +15 -3
- data/lib/callable_tree/node/internal/strategy/seek.rb +11 -1
- data/lib/callable_tree/node/internal/strategy.rb +10 -2
- data/lib/callable_tree/node/internal.rb +22 -28
- data/lib/callable_tree/node/root.rb +1 -0
- data/lib/callable_tree/version.rb +1 -1
- data/lib/callable_tree.rb +1 -0
- metadata +17 -11
- data/examples/builder/hooks-caller.rb +0 -38
- data/examples/hooks-caller.rb +0 -39
@@ -1,38 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'callable_tree'
|
4
|
-
|
5
|
-
Root =
|
6
|
-
CallableTree::Node::Internal::Builder
|
7
|
-
.new
|
8
|
-
.hookable
|
9
|
-
.build
|
10
|
-
|
11
|
-
Root
|
12
|
-
.new
|
13
|
-
.before_caller do |input, **_options|
|
14
|
-
puts "before_caller input: #{input}"
|
15
|
-
input + 1
|
16
|
-
end
|
17
|
-
.append(
|
18
|
-
# anonymous external node
|
19
|
-
lambda do |input, **_options|
|
20
|
-
puts "external input: #{input}"
|
21
|
-
input * 2
|
22
|
-
end
|
23
|
-
)
|
24
|
-
.around_caller do |input, **_options, &block|
|
25
|
-
puts "around_caller input: #{input}"
|
26
|
-
output = block.call
|
27
|
-
puts "around_caller output: #{output}"
|
28
|
-
output * input
|
29
|
-
end
|
30
|
-
.after_caller do |output, **_options|
|
31
|
-
puts "after_caller output: #{output}"
|
32
|
-
output * 2
|
33
|
-
end
|
34
|
-
.tap do |tree|
|
35
|
-
options = { foo: :bar }
|
36
|
-
output = tree.call(1, **options)
|
37
|
-
puts "result: #{output}"
|
38
|
-
end
|
data/examples/hooks-caller.rb
DELETED
@@ -1,39 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'callable_tree'
|
4
|
-
|
5
|
-
module Node
|
6
|
-
class HooksSample
|
7
|
-
include CallableTree::Node::Internal
|
8
|
-
prepend CallableTree::Node::Hooks::Caller
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
Node::HooksSample
|
13
|
-
.new
|
14
|
-
.before_caller do |input, **_options|
|
15
|
-
puts "before_caller input: #{input}"
|
16
|
-
input + 1
|
17
|
-
end
|
18
|
-
.append(
|
19
|
-
# anonymous external node
|
20
|
-
lambda do |input, **_options|
|
21
|
-
puts "external input: #{input}"
|
22
|
-
input * 2
|
23
|
-
end
|
24
|
-
)
|
25
|
-
.around_caller do |input, **_options, &block|
|
26
|
-
puts "around_caller input: #{input}"
|
27
|
-
output = block.call
|
28
|
-
puts "around_caller output: #{output}"
|
29
|
-
output * input
|
30
|
-
end
|
31
|
-
.after_caller do |output, **_options|
|
32
|
-
puts "after_caller output: #{output}"
|
33
|
-
output * 2
|
34
|
-
end
|
35
|
-
.tap do |tree|
|
36
|
-
options = { foo: :bar }
|
37
|
-
output = tree.call(1, **options)
|
38
|
-
puts "result: #{output}"
|
39
|
-
end
|