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.
Files changed (37) hide show
  1. checksums.yaml +4 -4
  2. data/.github/dependabot.yml +7 -0
  3. data/.github/workflows/build.yml +3 -5
  4. data/.github/workflows/codeql-analysis.yml +4 -4
  5. data/.rubocop.yml +6 -0
  6. data/.ruby-version +1 -1
  7. data/CHANGELOG.md +12 -0
  8. data/Gemfile.lock +3 -3
  9. data/README.md +460 -276
  10. data/callable_tree.gemspec +1 -0
  11. data/examples/builder/external-verbosify.rb +87 -0
  12. data/examples/builder/hooks.rb +67 -0
  13. data/examples/builder/identity.rb +91 -0
  14. data/examples/builder/internal-broadcastable.rb +11 -11
  15. data/examples/builder/internal-composable.rb +11 -11
  16. data/examples/builder/internal-seekable.rb +9 -15
  17. data/examples/builder/logging.rb +36 -39
  18. data/examples/{external-verbosify.rb → class/external-verbosify.rb} +3 -5
  19. data/examples/class/hooks.rb +70 -0
  20. data/examples/{identity.rb → class/identity.rb} +3 -5
  21. data/examples/{internal-broadcastable.rb → class/internal-broadcastable.rb} +0 -0
  22. data/examples/{internal-composable.rb → class/internal-composable.rb} +0 -0
  23. data/examples/{internal-seekable.rb → class/internal-seekable.rb} +3 -5
  24. data/examples/{logging.rb → class/logging.rb} +47 -47
  25. data/lib/callable_tree/node/builder.rb +13 -0
  26. data/lib/callable_tree/node/hooks/terminator.rb +99 -0
  27. data/lib/callable_tree/node/internal/strategy/broadcast.rb +19 -2
  28. data/lib/callable_tree/node/internal/strategy/compose.rb +15 -3
  29. data/lib/callable_tree/node/internal/strategy/seek.rb +11 -1
  30. data/lib/callable_tree/node/internal/strategy.rb +10 -2
  31. data/lib/callable_tree/node/internal.rb +22 -28
  32. data/lib/callable_tree/node/root.rb +1 -0
  33. data/lib/callable_tree/version.rb +1 -1
  34. data/lib/callable_tree.rb +1 -0
  35. metadata +17 -11
  36. data/examples/builder/hooks-caller.rb +0 -38
  37. 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
@@ -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