Class: GraphWeaver::Codegen::Scalar

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

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Scalar

Returns a new instance of Scalar.



41
42
43
# File 'lib/graph_weaver/codegen.rb', line 41

def initialize(name)
  @name = name
end

Instance Method Details

#bare_typeObject



45
46
47
# File 'lib/graph_weaver/codegen.rb', line 45

def bare_type
  SCALARS.fetch(@name, "T.untyped")
end

#cast(expr, _depth) ⇒ Object



53
54
55
# File 'lib/graph_weaver/codegen.rb', line 53

def cast(expr, _depth)
  SCALAR_CASTS.fetch(@name) { return expr }.call(expr)
end

#identity?Boolean

Returns:

  • (Boolean)


57
58
59
# File 'lib/graph_weaver/codegen.rb', line 57

def identity?
  !SCALAR_CASTS.key?(@name)
end

#nestedObject



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

def nested = nil

#non_null?Boolean

Returns:

  • (Boolean)


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

def non_null? = false

#prop_typeObject



49
50
51
# File 'lib/graph_weaver/codegen.rb', line 49

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

#serialize(expr, _depth) ⇒ Object



61
62
63
# File 'lib/graph_weaver/codegen.rb', line 61

def serialize(expr, _depth)
  SCALAR_SERIALIZERS.fetch(@name) { return expr }.call(expr)
end

#serialize_identity?Boolean

Returns:

  • (Boolean)


65
66
67
# File 'lib/graph_weaver/codegen.rb', line 65

def serialize_identity?
  !SCALAR_SERIALIZERS.key?(@name)
end