Class: GraphWeaver::Codegen::EnumNode
- Inherits:
-
Node
- Object
- Node
- GraphWeaver::Codegen::EnumNode
show all
- Defined in:
- lib/graph_weaver/codegen/nodes.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods inherited from Node
#hash_coerce_identity?, #identity?, #non_null?, #prop_type, #serialize_identity?
Constructor Details
#initialize(class_name, values) ⇒ EnumNode
Returns a new instance of EnumNode.
175
176
177
178
|
# File 'lib/graph_weaver/codegen/nodes.rb', line 175
def initialize(class_name, values)
@class_name = class_name
@values = values
end
|
Instance Attribute Details
#class_name ⇒ Object
Returns the value of attribute class_name.
173
174
175
|
# File 'lib/graph_weaver/codegen/nodes.rb', line 173
def class_name
@class_name
end
|
#values ⇒ Object
Returns the value of attribute values.
173
174
175
|
# File 'lib/graph_weaver/codegen/nodes.rb', line 173
def values
@values
end
|
Instance Method Details
#bare_type ⇒ Object
180
|
# File 'lib/graph_weaver/codegen/nodes.rb', line 180
def bare_type = class_name
|
#cast(expr, _depth) ⇒ Object
182
183
184
|
# File 'lib/graph_weaver/codegen/nodes.rb', line 182
def cast(expr, _depth)
"#{class_name}.deserialize(#{expr})"
end
|
#coerce(expr) ⇒ Object
194
195
196
|
# File 'lib/graph_weaver/codegen/nodes.rb', line 194
def coerce(expr)
"(#{expr}.is_a?(#{class_name}) ? #{expr} : #{class_name}.deserialize(#{expr}))"
end
|
#coerce? ⇒ Boolean
enums always coerce: a kwarg or hash field accepts the T::Enum or
its wire value (deserialize raises on anything else)
192
|
# File 'lib/graph_weaver/codegen/nodes.rb', line 192
def coerce? = true
|
198
|
# File 'lib/graph_weaver/codegen/nodes.rb', line 198
def coerce_input_type = "T.any(#{class_name}, String)"
|
#hash_coerce(expr, _depth) ⇒ Object
199
|
# File 'lib/graph_weaver/codegen/nodes.rb', line 199
def hash_coerce(expr, _depth) = coerce(expr)
|
#nested ⇒ Object
200
|
# File 'lib/graph_weaver/codegen/nodes.rb', line 200
def nested = self
|
#serialize(expr, _depth) ⇒ Object
186
187
188
|
# File 'lib/graph_weaver/codegen/nodes.rb', line 186
def serialize(expr, _depth)
"#{expr}.serialize"
end
|