Class: CallableTree::Node::External::Pod

Inherits:
Object
  • Object
show all
Includes:
CallableTree::Node::External
Defined in:
lib/callable_tree/node/external/pod.rb

Overview

Pod: A node that can be instantiated directly with proc-based behavior. Provides an alternative to Builder style for inline node creation.

Usage patterns:

Constructor style: Pod.new(caller: ->(input, **) { input * 2 })
Factory style: External.create(caller: ->(input, **) { input * 2 })
Block style: External.create { |node| node.caller { |input, **| input * 2 } }

Direct Known Subclasses

HookablePod

Instance Attribute Summary

Attributes included from CallableTree::Node

#parent

Instance Method Summary collapse

Methods included from CallableTree::Node::External

create, #external?, included, #internal?, #outline, #proxified?, proxify, #verbosified?, #verbosify, #verbosify!

Methods included from CallableTree::Node

#ancestors, #depth, #external?, #internal?, #outline, #root?, #routes

Constructor Details

#initialize(matcher: nil, caller: nil, terminator: nil, identifier: nil) {|_self| ... } ⇒ Pod

Returns a new instance of Pod.

Yields:

  • (_self)

Yield Parameters:



16
17
18
19
20
21
22
23
# File 'lib/callable_tree/node/external/pod.rb', line 16

def initialize(matcher: nil, caller: nil, terminator: nil, identifier: nil)
  @_matcher = matcher
  @_caller = caller
  @_terminator = terminator
  @_identifier = identifier

  yield self if block_given?
end

Instance Method Details

#call(*inputs, **options) ⇒ Object



54
55
56
57
58
59
60
# File 'lib/callable_tree/node/external/pod.rb', line 54

def call(*inputs, **options)
  raise ::CallableTree::Error, 'caller is not set' unless @_caller

  @_caller.call(*inputs, **options, _node_: self) do |*a, **o|
    super(*a, **o)
  end
end

#caller(proc = nil, &block) ⇒ Object



31
32
33
34
# File 'lib/callable_tree/node/external/pod.rb', line 31

def caller(proc = nil, &block)
  @_caller = proc || block
  self
end

#identifier(proc = nil, &block) ⇒ Object



41
42
43
44
# File 'lib/callable_tree/node/external/pod.rb', line 41

def identifier(proc = nil, &block)
  @_identifier = proc || block
  self
end

#identityObject



70
71
72
73
74
# File 'lib/callable_tree/node/external/pod.rb', line 70

def identity
  return super unless @_identifier

  @_identifier.call(_node_: self) { super }
end

#match?(*inputs, **options) ⇒ Boolean

Returns:

  • (Boolean)


46
47
48
49
50
51
52
# File 'lib/callable_tree/node/external/pod.rb', line 46

def match?(*inputs, **options)
  return super unless @_matcher

  @_matcher.call(*inputs, **options, _node_: self) do |*a, **o|
    super(*a, **o)
  end
end

#matcher(proc = nil, &block) ⇒ Object

DSL setters for block syntax



26
27
28
29
# File 'lib/callable_tree/node/external/pod.rb', line 26

def matcher(proc = nil, &block)
  @_matcher = proc || block
  self
end

#terminate?(output, *inputs, **options) ⇒ Boolean

Returns:

  • (Boolean)


62
63
64
65
66
67
68
# File 'lib/callable_tree/node/external/pod.rb', line 62

def terminate?(output, *inputs, **options)
  return super unless @_terminator

  @_terminator.call(output, *inputs, **options, _node_: self) do |o, *a, **opts|
    super(o, *a, **opts)
  end
end

#terminator(proc = nil, &block) ⇒ Object



36
37
38
39
# File 'lib/callable_tree/node/external/pod.rb', line 36

def terminator(proc = nil, &block)
  @_terminator = proc || block
  self
end