Class: Plumb::FilteredHash

Inherits:
Function show all
Defined in:
lib/plumb/hash_class.rb

Overview

The typed node returned by HashClass#filtered. It is a Function — so #>> treats it as a conversion (subtype by its output, accepted by its input) and it bypasses the strict composition check — declaring input_type as the filtered schema and output_type as that schema with all keys optional. But unlike a plain Function it does NOT strict-validate its input: #call runs the lenient filter, which accepts any Hash and drops invalid/missing/extra fields.

Instance Attribute Summary

Attributes inherited from Function

#children, #fn, #identity, #input_type, #output_type

Instance Method Summary collapse

Methods inherited from Function

#==, [], #absorb_input, #absorb_output, #fuse_with, #initialize, opaque, #standard_call?, #wraps_callable?

Methods included from TypedStep

#checks_output?, #fusable_step?, #opaque?, #standard_call?, #subtype_identity

Methods included from Composable

#&, #/, #>>, #[], #absorb_input, #absorb_output, #as_node, #build, #check, #children, #defer, #fusable_step?, #fuse_with, #generate, #idempotent?, included, #input_type, #invalid, #invoke, #match, #metadata, #not, #output_type, #pipeline, #policy, resolve_operand, #static, #subtype_identity, #to_json_schema, #to_mermaid, #to_plumb_type, #to_s, #transform, #value, #value_preserving?, #where, #with, wrap, #|

Methods included from Callable

#parse, #resolve

Constructor Details

This class inherits a constructor from Plumb::Function

Instance Method Details

#accepted_typeObject

A filtered Hash is lenient: it accepts ANY hash and drops invalid/missing/ extra fields (it never rejects a Hash), so as a #>> consumer it accepts any hash-like value. (Its #input_type still declares the schema it relaxes.)



456
# File 'lib/plumb/hash_class.rb', line 456

def accepted_type = Types::EachPair

#call(result) ⇒ Object

Neither boundary check runs — the per-field validation in HashClass#filtered subsumes both. Overriding #call is also what excludes this node from fusion, with nothing further to declare. @see Function#fusable_step?



466
# File 'lib/plumb/hash_class.rb', line 466

def call(result) = fn.call(result)

#node_nameObject

Naming derives #node_name when Composable is included (on Function), so the subclass would otherwise inherit :function.



451
# File 'lib/plumb/hash_class.rb', line 451

def node_name = :filtered_hash

#with_children(children) ⇒ Object

Re-derived, NOT rebuilt around the old #fn: the filter closes over the schema it was built from, so Function#with_children returns a node that inspects as the new schema and still filters by the old one.



461
# File 'lib/plumb/hash_class.rb', line 461

def with_children(children) = children.first.filtered