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

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Function

#==, [], #absorb_input, #absorb_output, #fuse_with, #initialize, opaque, #standard_call?, #with_children, #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

Class Method Details

.each_pair_interfaceObject

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.) Memoized at the class level (instances are frozen; Types isn't loaded yet when this file is).



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

def self.each_pair_interface = @each_pair_interface ||= Types::Interface[:each_pair]

Instance Method Details

#accepted_typeObject



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

def accepted_type = FilteredHash.each_pair_interface

#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?



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

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