Class: GraphWeaver::Codegen::Scalar

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

Instance Method Summary collapse

Constructor Details

#initialize(scalar_type) ⇒ Scalar

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



11
12
13
# File 'lib/graph_weaver/codegen/nodes.rb', line 11

def initialize(scalar_type)
  @scalar = scalar_type
end

Instance Method Details

#bare_type ⇒ Object



15
16
17
# File 'lib/graph_weaver/codegen/nodes.rb', line 15

def bare_type
  @scalar.type
end

#cast(expr, _depth) ⇒ Object



25
26
27
# File 'lib/graph_weaver/codegen/nodes.rb', line 25

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

#coerce(expr) ⇒ Object



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

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)


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

def coerce? = @scalar.coerce?

#coerce_input_type ⇒ Object



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

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



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

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

#hash_coerce_identity? ⇒ Boolean

Returns:

  • (Boolean)


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

def hash_coerce_identity? = !@scalar.coerce?

#identity? ⇒ Boolean

Returns:

  • (Boolean)


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

def identity?
  !@scalar.cast?
end

#nested ⇒ Object



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

def nested = nil

#non_null? ⇒ Boolean

Returns:

  • (Boolean)


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

def non_null? = false

#prop_type ⇒ Object



19
20
21
22
23
# File 'lib/graph_weaver/codegen/nodes.rb', line 19

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



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

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

#serialize_identity? ⇒ Boolean

Returns:

  • (Boolean)


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

def serialize_identity?
  !@scalar.serialize?
end