Class: GraphWeaver::Codegen::Scalar
- Inherits:
-
Object
- Object
- 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.
- #nested ⇒ Object
- #non_null? ⇒ Boolean
- #prop_type ⇒ Object
- #serialize(expr, _depth) ⇒ Object
- #serialize_identity? ⇒ Boolean
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 @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.
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
54 |
# File 'lib/graph_weaver/codegen/nodes.rb', line 54 def hash_coerce_identity? = !@scalar.coerce? |
#identity? ⇒ 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
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 == "T.untyped" ? : "T.nilable(#{})" 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
37 38 39 |
# File 'lib/graph_weaver/codegen/nodes.rb', line 37 def serialize_identity? !@scalar.serialize? end |