Sha256: 6b195bbfa2e934ce98acd86182dd7bc7a0fbdfb2f50dc74163f5ec0460f625d9
Contents?: true
Size: 1.3 KB
Versions: 2
Compression:
Stored size: 1.3 KB
Contents
# typed: strict # frozen_string_literal: true module Yogurt class CodeGenerator # Input classes are used for input objects class InputClass < T::Struct extend T::Sig include Utils include DefinedClass const :name, String const :arguments, T::Array[VariableDefinition] sig {override.returns(T::Array[String])} def dependencies arguments.map(&:dependency).compact end sig {override.returns(String)} def to_ruby extract = [] props = [] serializers = [] arguments.sort.each do |definition| props << "prop #{definition.name.inspect}, #{definition.signature}" extract << "#{definition.name} = self.#{definition.name}" serializers.push(<<~STRING.strip) #{definition.graphql_name.inspect} => #{definition.serializer.strip}, STRING end <<~STRING class #{name} < T::Struct extend T::Sig #{indent(props.join("\n"), 1).strip} sig {returns(T::Hash[String, T.untyped])} def serialize #{indent(extract.join("\n"), 2).strip} { #{indent(serializers.join("\n"), 3).strip} } end end STRING end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
yogurt-0.2.0 | lib/yogurt/code_generator/input_class.rb |
yogurt-0.1.1 | lib/yogurt/code_generator/input_class.rb |