callable_tree 0.3.7 → 0.3.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +6 -0
- data/.ruby-version +1 -1
- data/CHANGELOG.md +6 -0
- data/Gemfile.lock +1 -1
- data/README.md +366 -108
- data/callable_tree.gemspec +1 -0
- data/examples/builder/hooks.rb +67 -0
- data/examples/builder/logging.rb +33 -30
- data/examples/{external-verbosify.rb → class/external-verbosify.rb} +1 -1
- data/examples/class/hooks.rb +70 -0
- data/examples/{identity.rb → class/identity.rb} +1 -1
- 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} +1 -1
- data/examples/{logging.rb → class/logging.rb} +45 -43
- data/lib/callable_tree/node/builder.rb +13 -0
- data/lib/callable_tree/node/hooks/terminator.rb +99 -0
- 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 +14 -11
- data/examples/builder/hooks-caller.rb +0 -38
- data/examples/hooks-caller.rb +0 -39
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
|