Class: GraphWeaver::Codegen::EnumNode

Inherits:
Node
  • Object
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.



171
172
173
174
# File 'lib/graph_weaver/codegen/nodes.rb', line 171

def initialize(class_name, values)
  @class_name = class_name
  @values = values
end

Instance Attribute Details

#class_nameObject (readonly)

Returns the value of attribute class_name.



169
170
171
# File 'lib/graph_weaver/codegen/nodes.rb', line 169

def class_name
  @class_name
end

#valuesObject (readonly)

Returns the value of attribute values.



169
170
171
# File 'lib/graph_weaver/codegen/nodes.rb', line 169

def values
  @values
end

Instance Method Details

#bare_typeObject



176
# File 'lib/graph_weaver/codegen/nodes.rb', line 176

def bare_type = class_name

#cast(expr, _depth) ⇒ Object



178
179
180
# File 'lib/graph_weaver/codegen/nodes.rb', line 178

def cast(expr, _depth)
  "#{class_name}.deserialize(#{expr})"
end

#coerce(expr) ⇒ Object



190
191
192
# File 'lib/graph_weaver/codegen/nodes.rb', line 190

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)

Returns:

  • (Boolean)


188
# File 'lib/graph_weaver/codegen/nodes.rb', line 188

def coerce? = true

#coerce_input_typeObject



194
# File 'lib/graph_weaver/codegen/nodes.rb', line 194

def coerce_input_type = "T.any(#{class_name}, String)"

#hash_coerce(expr, _depth) ⇒ Object



195
# File 'lib/graph_weaver/codegen/nodes.rb', line 195

def hash_coerce(expr, _depth) = coerce(expr)

#nestedObject



196
# File 'lib/graph_weaver/codegen/nodes.rb', line 196

def nested = self

#serialize(expr, _depth) ⇒ Object



182
183
184
# File 'lib/graph_weaver/codegen/nodes.rb', line 182

def serialize(expr, _depth)
  "#{expr}.serialize"
end