Class: GraphWeaver::Codegen::List

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

Instance Method Summary collapse

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_typeObject



93
94
95
# File 'lib/graph_weaver/codegen.rb', line 93

def bare_type
  "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

Returns:

  • (Boolean)


112
# File 'lib/graph_weaver/codegen.rb', line 112

def identity? = @of.identity?

#nestedObject



127
# File 'lib/graph_weaver/codegen.rb', line 127

def nested = @of.nested

#non_null?Boolean

Returns:

  • (Boolean)


126
# File 'lib/graph_weaver/codegen.rb', line 126

def non_null? = false

#prop_typeObject



97
98
99
# File 'lib/graph_weaver/codegen.rb', line 97

def prop_type
  "T.nilable(#{bare_type})"
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

Returns:

  • (Boolean)


125
# File 'lib/graph_weaver/codegen.rb', line 125

def serialize_identity? = @of.serialize_identity?