Class: Yogurt::CodeGenerator::InputClass
- Inherits:
-
T::Struct
- Object
- T::Struct
- Yogurt::CodeGenerator::InputClass
- Extended by:
- T::Sig
- Includes:
- DefinedClass, Utils
- Defined in:
- lib/yogurt/code_generator/input_class.rb
Overview
Input classes are used for input objects
Instance Method Summary collapse
Methods included from DefinedClass
Methods included from Utils
#camelize, #generate_method_name, #generate_pretty_print, #indent, #possible_types_constant, #typename_method, #underscore
Instance Method Details
#dependencies ⇒ Object
16 17 18 |
# File 'lib/yogurt/code_generator/input_class.rb', line 16 def dependencies arguments.map(&:dependency).compact end |
#to_ruby ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/yogurt/code_generator/input_class.rb', line 21 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 |