Class: GraphWeaver::Codegen::InputNode

Inherits:
Object
  • Object
show all
Defined in:
lib/graph_weaver/codegen/nodes.rb

Overview

An input-object variable: emitted as a module-level T::Struct whose serialize produces the wire hash. Inputs never cast FROM the wire. Joins the coerce protocol so execute kwargs accept plain hashes, normalized (and type-checked) through the generated .coerce.

Defined Under Namespace

Classes: Field

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(class_name) ⇒ InputNode

Returns a new instance of InputNode.



323
324
325
326
# File 'lib/graph_weaver/codegen/nodes.rb', line 323

def initialize(class_name)
  @class_name = class_name
  @fields = []
end

Instance Attribute Details

#class_name ⇒ Object (readonly)

Returns the value of attribute class_name.



321
322
323
# File 'lib/graph_weaver/codegen/nodes.rb', line 321

def class_name
  @class_name
end

#fields ⇒ Object (readonly)

Returns the value of attribute fields.



321
322
323
# File 'lib/graph_weaver/codegen/nodes.rb', line 321

def fields
  @fields
end

Instance Method Details

#bare_type ⇒ Object



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

def bare_type = class_name

#cast(_expr, _depth) ⇒ Object

Raises:

  • (NotImplementedError)


340
341
342
# File 'lib/graph_weaver/codegen/nodes.rb', line 340

def cast(_expr, _depth)
  raise NotImplementedError, "input objects are never cast from responses"
end

#coerce(expr) ⇒ Object



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

def coerce(expr) = "#{class_name}.coerce(#{expr})"

#coerce? ⇒ Boolean

Returns:

  • (Boolean)


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

def coerce? = true

#coerce_input_type ⇒ Object



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

def coerce_input_type = "T.any(#{class_name}, T::Hash[T.untyped, T.untyped])"

#hash_coerce(expr, _depth) ⇒ Object

building a struct field from a caller-supplied plain hash value



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

def hash_coerce(expr, _depth) = "#{class_name}.coerce(#{expr})"

#hash_coerce_identity? ⇒ Boolean

Returns:

  • (Boolean)


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

def hash_coerce_identity? = false

#identity? ⇒ Boolean

Returns:

  • (Boolean)


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

def identity? = false

#nested ⇒ Object



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

def nested = nil

#non_null? ⇒ Boolean

Returns:

  • (Boolean)


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

def non_null? = false

#prop_type ⇒ Object



330
331
332
# File 'lib/graph_weaver/codegen/nodes.rb', line 330

def prop_type
  "T.nilable(#{bare_type})"
end

#serialize(expr, _depth) ⇒ Object



334
335
336
# File 'lib/graph_weaver/codegen/nodes.rb', line 334

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

#serialize_identity? ⇒ Boolean

Returns:

  • (Boolean)


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

def serialize_identity? = false