Class: GraphWeaver::Codegen::Scalar
- Defined in:
- lib/graph_weaver/codegen/nodes.rb
Instance Method Summary collapse
- #bare_type ⇒ Object
- #cast(expr, _depth) ⇒ Object
- #coerce(expr) ⇒ Object
-
#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).
- #coerce_input_type ⇒ Object
-
#hash_coerce(expr, _depth) ⇒ Object
inside input-struct hashes, scalars coerce exactly like variable kwargs do — the registry (incl. GraphWeaver.auto_coerce) decides.
- #hash_coerce_identity? ⇒ Boolean
- #identity? ⇒ Boolean
-
#initialize(scalar_type) ⇒ Scalar
constructor
takes a resolved ScalarType — the generator picks it from the client-scoped overlay or the global registry.
- #prop_type ⇒ Object
- #serialize(expr, _depth) ⇒ Object
- #serialize_identity? ⇒ Boolean
Methods inherited from Node
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_type ⇒ Object
33 34 35 |
# File 'lib/graph_weaver/codegen/nodes.rb', line 33 def @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.
62 |
# File 'lib/graph_weaver/codegen/nodes.rb', line 62 def coerce? = @scalar.coerce? |
#coerce_input_type ⇒ Object
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
72 |
# File 'lib/graph_weaver/codegen/nodes.rb', line 72 def hash_coerce_identity? = !@scalar.coerce? |
#identity? ⇒ Boolean
47 48 49 |
# File 'lib/graph_weaver/codegen/nodes.rb', line 47 def identity? !@scalar.cast? end |
#prop_type ⇒ Object
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 == "T.untyped" ? : "T.nilable(#{})" 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
55 56 57 |
# File 'lib/graph_weaver/codegen/nodes.rb', line 55 def serialize_identity? !@scalar.serialize? end |