Class: Plumb::Composable::Node
- Inherits:
-
Object
- Object
- Plumb::Composable::Node
- Includes:
- Plumb::Composable
- Defined in:
- lib/plumb/composable.rb
Overview
Support #as_node.
Instance Attribute Summary collapse
-
#args ⇒ Object
readonly
Returns the value of attribute args.
-
#node_name ⇒ Object
readonly
Returns the value of attribute node_name.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
-
#==(other) ⇒ Object
Two nodes are equal when they wrap the same type with the same node_name and args.
- #call(result) ⇒ Object
-
#initialize(node_name, type, args = BLANK_HASH) ⇒ Node
constructor
A new instance of Node.
-
#input_type ⇒ Object
A Node is a transparent wrapper (it only re-labels its node_name): it delegates type-flow to the wrapped type.
-
#metadata(data = Undefined) ⇒ Object
When wrapping a node in Metadata we need to preserte the Node with cistom node_name.
- #output_type ⇒ Object
- #value_preserving? ⇒ Boolean
Methods included from Plumb::Composable
#&, #/, #>>, #[], #absorb_input, #absorb_output, #accepted_type, #as_node, #build, #check, #children, #defer, #fusable_step?, #fuse_with, #generate, #idempotent?, included, #invalid, #invoke, #match, #not, #pipeline, #policy, resolve_operand, #static, #subtype_identity, #to_json_schema, #to_mermaid, #to_plumb_type, #to_s, #transform, #value, #where, #with, wrap, #|
Methods included from Plumb::Callable
Constructor Details
#initialize(node_name, type, args = BLANK_HASH) ⇒ Node
Returns a new instance of Node.
630 631 632 633 634 635 |
# File 'lib/plumb/composable.rb', line 630 def initialize(node_name, type, args = BLANK_HASH) @node_name = node_name @type = type @args = args freeze end |
Instance Attribute Details
#args ⇒ Object (readonly)
Returns the value of attribute args.
628 629 630 |
# File 'lib/plumb/composable.rb', line 628 def args @args end |
#node_name ⇒ Object (readonly)
Returns the value of attribute node_name.
628 629 630 |
# File 'lib/plumb/composable.rb', line 628 def node_name @node_name end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
628 629 630 |
# File 'lib/plumb/composable.rb', line 628 def type @type end |
Instance Method Details
#==(other) ⇒ Object
Two nodes are equal when they wrap the same type with the same node_name and args. The default Composable#== compares #children, but a Node holds its identity in @node_name/@type/@args, so without this every as_node-wrapped type (Email, Boolean, etc.) would compare equal to every other.
667 668 669 670 671 672 |
# File 'lib/plumb/composable.rb', line 667 def ==(other) other.is_a?(self.class) && other.node_name == node_name && other.type == type && other.args == args end |
#call(result) ⇒ Object
649 |
# File 'lib/plumb/composable.rb', line 649 def call(result) = type.call(result) |
#input_type ⇒ Object
A Node is a transparent wrapper (it only re-labels its node_name): it delegates type-flow to the wrapped type.
653 |
# File 'lib/plumb/composable.rb', line 653 def input_type = type.input_type |
#metadata(data = Undefined) ⇒ Object
When wrapping a node in Metadata we need to preserte the Node with cistom node_name. but when just querying metadata, we can delegate to the underlying type.
641 642 643 644 645 646 647 |
# File 'lib/plumb/composable.rb', line 641 def (data = Undefined) if data == Undefined type. else Metadata.new(self, data) end end |
#output_type ⇒ Object
654 |
# File 'lib/plumb/composable.rb', line 654 def output_type = type.output_type |
#value_preserving? ⇒ Boolean
655 |
# File 'lib/plumb/composable.rb', line 655 def value_preserving? = type.value_preserving? |