Class: Plumb::StaticClass

Inherits:
Object
  • Object
show all
Includes:
Composable
Defined in:
lib/plumb/static_class.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Composable

#&, #/, #>>, #absorb_input, #absorb_output, #accepted_type, #as_node, #build, #check, #defer, #fusable_step?, #fuse_with, #generate, #idempotent?, included, #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

#initialize(value = Undefined) ⇒ StaticClass

Returns a new instance of StaticClass.

Raises:

  • (ArgumentError)


11
12
13
14
15
16
17
# File 'lib/plumb/static_class.rb', line 11

def initialize(value = Undefined)
  raise ArgumentError, 'value must be frozen' unless value.frozen?

  @value = value
  @children = [value].freeze
  freeze
end

Instance Attribute Details

#childrenObject (readonly)

Returns the value of attribute children.



9
10
11
# File 'lib/plumb/static_class.rb', line 9

def children
  @children
end

Instance Method Details

#[](value) ⇒ Object



19
20
21
# File 'lib/plumb/static_class.rb', line 19

def [](value)
  self.class.new(value)
end

#call(result) ⇒ Object



42
43
44
# File 'lib/plumb/static_class.rb', line 42

def call(result)
  result.valid!(@value)
end

#input_typeObject

A static step ignores its input and always emits a fixed value. Its input is therefore Any — it accepts anything, so it opts out of #>> checks on the input side (eg. as the right of Undefined >> Static[x]). Its output is the value itself (the default #output_type — this atomic node wraps the value), so a successor that could never accept that value is caught at composition time, eg. Types::Static['foo'] >> Types::Integer raises.



29
# File 'lib/plumb/static_class.rb', line 29

def input_type = Types::Any

#subtype_of?(other) ⇒ Boolean

Tests the concrete produced value directly. Atomic matcher logic is unsuitable here because it models matched values and widens numeric equality domains.

Parameters:

Returns:

  • (Boolean)


35
36
37
38
39
40
# File 'lib/plumb/static_class.rb', line 35

def subtype_of?(other)
  return true if self == other
  return super if @value.is_a?(Composable)

  other === @value
end