Class: GraphWeaver::Codegen::Scalar

Inherits:
Node
  • Object
show all
Defined in:
lib/graph_weaver/codegen/nodes.rb

Instance Method Summary collapse

Methods inherited from Node

#nested, #non_null?

Constructor Details

#initialize(scalar_type) ⇒ Scalar

takes a resolved ScalarType — the generator picks it from the client-scoped overlay or the global registry



29
30
31
# File 'lib/graph_weaver/codegen/nodes.rb', line 29

def initialize(scalar_type)
  @scalar = scalar_type
end

Instance Method Details

#bare_typeObject



33
34
35
# File 'lib/graph_weaver/codegen/nodes.rb', line 33

def bare_type
  @scalar.type
end

#cast(expr, _depth) ⇒ Object



43
44
45
# File 'lib/graph_weaver/codegen/nodes.rb', line 43

def cast(expr, _depth)
  @scalar.cast(expr)
end

#coerce(expr) ⇒ Object



63
# File 'lib/graph_weaver/codegen/nodes.rb', line 63

def coerce(expr) = @scalar.coerce_input(expr)

#coerce?Boolean

coercion (opt-in per scalar): accept the value or its raw input and normalize before serializing — parse for a rich type (coerce: true), or a plain conversion for built-ins (coerce: :to_f). See ScalarType.

Returns:

  • (Boolean)


62
# File 'lib/graph_weaver/codegen/nodes.rb', line 62

def coerce? = @scalar.coerce?

#coerce_input_typeObject



64
# File 'lib/graph_weaver/codegen/nodes.rb', line 64

def coerce_input_type = @scalar.coerce_type

#hash_coerce(expr, _depth) ⇒ Object

inside input-struct hashes, scalars coerce exactly like variable kwargs do — the registry (incl. GraphWeaver.auto_coerce) decides



68
69
70
# File 'lib/graph_weaver/codegen/nodes.rb', line 68

def hash_coerce(expr, _depth)
  @scalar.coerce_input(expr) || expr
end

#hash_coerce_identity?Boolean

Returns:

  • (Boolean)


72
# File 'lib/graph_weaver/codegen/nodes.rb', line 72

def hash_coerce_identity? = !@scalar.coerce?

#identity?Boolean

Returns:

  • (Boolean)


47
48
49
# File 'lib/graph_weaver/codegen/nodes.rb', line 47

def identity?
  !@scalar.cast?
end

#prop_typeObject



37
38
39
40
41
# File 'lib/graph_weaver/codegen/nodes.rb', line 37

def prop_type
  # unregistered scalars are already T.untyped — wrapping in
  # T.nilable is redundant and an srb tc error under typed: strict
  bare_type == "T.untyped" ? bare_type : "T.nilable(#{bare_type})"
end

#serialize(expr, _depth) ⇒ Object



51
52
53
# File 'lib/graph_weaver/codegen/nodes.rb', line 51

def serialize(expr, _depth)
  @scalar.serialize(expr)
end

#serialize_identity?Boolean

Returns:

  • (Boolean)


55
56
57
# File 'lib/graph_weaver/codegen/nodes.rb', line 55

def serialize_identity?
  !@scalar.serialize?
end