Class: GraphWeaver::Codegen::List
- Inherits:
-
Object
- Object
- GraphWeaver::Codegen::List
- Defined in:
- lib/graph_weaver/codegen.rb
Instance Method Summary collapse
- #bare_type ⇒ Object
- #cast(expr, depth) ⇒ Object
- #identity? ⇒ Boolean
-
#initialize(of) ⇒ List
constructor
A new instance of List.
- #nested ⇒ Object
- #non_null? ⇒ Boolean
- #prop_type ⇒ Object
- #serialize(expr, depth) ⇒ Object
- #serialize_identity? ⇒ Boolean
Constructor Details
#initialize(of) ⇒ List
Returns a new instance of List.
89 90 91 |
# File 'lib/graph_weaver/codegen.rb', line 89 def initialize(of) @of = of end |
Instance Method Details
#bare_type ⇒ Object
93 94 95 |
# File 'lib/graph_weaver/codegen.rb', line 93 def "T::Array[#{@of.prop_type}]" end |
#cast(expr, depth) ⇒ Object
101 102 103 104 105 106 107 108 109 110 |
# File 'lib/graph_weaver/codegen.rb', line 101 def cast(expr, depth) var = "v#{depth}" element = if @of.non_null? || @of.identity? @of.identity? ? var : @of.cast(var, depth + 1) else "#{var}&.then { |v#{depth + 1}| #{@of.cast("v#{depth + 1}", depth + 2)} }" end "#{expr}.map { |#{var}| #{element} }" end |
#identity? ⇒ Boolean
112 |
# File 'lib/graph_weaver/codegen.rb', line 112 def identity? = @of.identity? |
#nested ⇒ Object
127 |
# File 'lib/graph_weaver/codegen.rb', line 127 def nested = @of.nested |
#non_null? ⇒ Boolean
126 |
# File 'lib/graph_weaver/codegen.rb', line 126 def non_null? = false |
#prop_type ⇒ Object
97 98 99 |
# File 'lib/graph_weaver/codegen.rb', line 97 def prop_type "T.nilable(#{})" end |
#serialize(expr, depth) ⇒ Object
114 115 116 117 118 119 120 121 122 123 |
# File 'lib/graph_weaver/codegen.rb', line 114 def serialize(expr, depth) var = "v#{depth}" element = if @of.non_null? || @of.serialize_identity? @of.serialize_identity? ? var : @of.serialize(var, depth + 1) else "#{var}&.then { |v#{depth + 1}| #{@of.serialize("v#{depth + 1}", depth + 2)} }" end "#{expr}.map { |#{var}| #{element} }" end |
#serialize_identity? ⇒ Boolean
125 |
# File 'lib/graph_weaver/codegen.rb', line 125 def serialize_identity? = @of.serialize_identity? |