Class: GraphWeaver::Codegen::Scalar
- Inherits:
-
Object
- Object
- GraphWeaver::Codegen::Scalar
- Defined in:
- lib/graph_weaver/codegen.rb
Instance Method Summary collapse
- #bare_type ⇒ Object
- #cast(expr, _depth) ⇒ Object
- #identity? ⇒ Boolean
-
#initialize(name) ⇒ Scalar
constructor
A new instance of Scalar.
- #nested ⇒ Object
- #non_null? ⇒ Boolean
- #prop_type ⇒ Object
- #serialize(expr, _depth) ⇒ Object
- #serialize_identity? ⇒ Boolean
Constructor Details
#initialize(name) ⇒ Scalar
Returns a new instance of Scalar.
41 42 43 |
# File 'lib/graph_weaver/codegen.rb', line 41 def initialize(name) @name = name end |
Instance Method Details
#bare_type ⇒ Object
45 46 47 |
# File 'lib/graph_weaver/codegen.rb', line 45 def SCALARS.fetch(@name, "T.untyped") end |
#cast(expr, _depth) ⇒ Object
53 54 55 |
# File 'lib/graph_weaver/codegen.rb', line 53 def cast(expr, _depth) SCALAR_CASTS.fetch(@name) { return expr }.call(expr) end |
#identity? ⇒ Boolean
57 58 59 |
# File 'lib/graph_weaver/codegen.rb', line 57 def identity? !SCALAR_CASTS.key?(@name) end |
#nested ⇒ Object
70 |
# File 'lib/graph_weaver/codegen.rb', line 70 def nested = nil |
#non_null? ⇒ Boolean
69 |
# File 'lib/graph_weaver/codegen.rb', line 69 def non_null? = false |
#prop_type ⇒ Object
49 50 51 |
# File 'lib/graph_weaver/codegen.rb', line 49 def prop_type "T.nilable(#{})" end |
#serialize(expr, _depth) ⇒ Object
61 62 63 |
# File 'lib/graph_weaver/codegen.rb', line 61 def serialize(expr, _depth) SCALAR_SERIALIZERS.fetch(@name) { return expr }.call(expr) end |
#serialize_identity? ⇒ Boolean
65 66 67 |
# File 'lib/graph_weaver/codegen.rb', line 65 def serialize_identity? !SCALAR_SERIALIZERS.key?(@name) end |