Class: GraphWeaver::Codegen::List
- Inherits:
-
Object
- Object
- GraphWeaver::Codegen::List
- Defined in:
- lib/graph_weaver/codegen/nodes.rb
Instance Attribute Summary collapse
-
#of ⇒ Object
readonly
Returns the value of attribute of.
Instance Method Summary collapse
- #bare_type ⇒ Object
- #cast(expr, depth) ⇒ Object
- #coerce? ⇒ Boolean
- #hash_coerce(expr, depth) ⇒ Object
- #hash_coerce_identity? ⇒ Boolean
- #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.
85 86 87 |
# File 'lib/graph_weaver/codegen/nodes.rb', line 85 def initialize(of) @of = of end |
Instance Attribute Details
#of ⇒ Object (readonly)
Returns the value of attribute of.
83 84 85 |
# File 'lib/graph_weaver/codegen/nodes.rb', line 83 def of @of end |
Instance Method Details
#bare_type ⇒ Object
89 90 91 |
# File 'lib/graph_weaver/codegen/nodes.rb', line 89 def "T::Array[#{@of.prop_type}]" end |
#cast(expr, depth) ⇒ Object
97 98 99 100 101 102 103 104 105 106 |
# File 'lib/graph_weaver/codegen/nodes.rb', line 97 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 |
#coerce? ⇒ Boolean
122 |
# File 'lib/graph_weaver/codegen/nodes.rb', line 122 def coerce? = false |
#hash_coerce(expr, depth) ⇒ Object
124 125 126 127 128 129 130 131 132 133 |
# File 'lib/graph_weaver/codegen/nodes.rb', line 124 def hash_coerce(expr, depth) var = "v#{depth}" inner = if @of.non_null? || @of.hash_coerce_identity? @of.hash_coerce_identity? ? var : @of.hash_coerce(var, depth + 1) else "#{var}&.then { |v#{depth + 1}| #{@of.hash_coerce("v#{depth + 1}", depth + 2)} }" end "#{expr}.map { |#{var}| #{inner} }" end |
#hash_coerce_identity? ⇒ Boolean
135 |
# File 'lib/graph_weaver/codegen/nodes.rb', line 135 def hash_coerce_identity? = @of.hash_coerce_identity? |
#identity? ⇒ Boolean
108 |
# File 'lib/graph_weaver/codegen/nodes.rb', line 108 def identity? = @of.identity? |
#nested ⇒ Object
137 |
# File 'lib/graph_weaver/codegen/nodes.rb', line 137 def nested = @of.nested |
#non_null? ⇒ Boolean
136 |
# File 'lib/graph_weaver/codegen/nodes.rb', line 136 def non_null? = false |
#prop_type ⇒ Object
93 94 95 |
# File 'lib/graph_weaver/codegen/nodes.rb', line 93 def prop_type "T.nilable(#{})" end |
#serialize(expr, depth) ⇒ Object
110 111 112 113 114 115 116 117 118 119 |
# File 'lib/graph_weaver/codegen/nodes.rb', line 110 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
121 |
# File 'lib/graph_weaver/codegen/nodes.rb', line 121 def serialize_identity? = @of.serialize_identity? |