Class: Foobara::RemoteGenerator::Services::CommandCastResultGenerator

Inherits:
CommandResultGenerator show all
Defined in:
foobara-typescript-remote-command-generator-1.2.0/src/remote_generator/services/command_cast_result_generator.rb

Defined Under Namespace

Classes: CastTree

Constant Summary

Constants included from TruncatedInspect

TruncatedInspect::MAX_LENGTH

Instance Attribute Summary

Attributes inherited from FilesGenerator

#belongs_to_dependency_group, #relevant_manifest

Instance Method Summary collapse

Methods inherited from CommandResultGenerator

#association_depth, #model_generators, #type_generators

Methods inherited from CommandGenerator

#base_class_name, #base_class_path, #command_errors_index_generator, #domain_generator, #errors_in_this_namespace, #result_json_requires_cast?

Methods inherited from TypescriptFromManifestBaseGenerator

#==, #attributes_to_ts_type, #custom_type_to_ts_type_name, #dependency_group, #dependency_roots, #foobara_type_to_ts_type, #hash, #import_destructure, #import_path, #import_path_array, #initialize, manifest_to_generator_classes, #model_to_ts_model_name, #parent, #path_to_root, #templates_dir, #ts_instance_full_name, #ts_instance_full_path, #ts_instance_path, #ts_type_full_path, #value_to_ts_value

Methods inherited from FilesGenerator

#==, #absolute_template_path, #dependencies_to_generate, #eql?, #erb_template, #generate, generator_for, #generator_for, generators_for, #generators_for, #hash, #initialize, manifest_to_generator_classes, #method_missing, #path_to_root, #respond_to_missing?, #target_dir, #template_string, #templates_dir

Methods included from TruncatedInspect

#inspect, truncating

Constructor Details

This class inherits a constructor from Foobara::RemoteGenerator::Services::TypescriptFromManifestBaseGenerator

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Foobara::FilesGenerator

Instance Method Details

#aggregate?Boolean

Returns:

  • (Boolean)


78
79
80
# File 'src/remote_generator/services/command_cast_result_generator.rb', line 78

def aggregate?
  serializers&.any? { |s| s == "Foobara::CommandConnectors::Serializers::AggregateSerializer" }
end

#applicable?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'src/remote_generator/services/command_cast_result_generator.rb', line 35

def applicable?
  result_json_requires_cast?
end

#atom?Boolean

Returns:

  • (Boolean)


74
75
76
# File 'src/remote_generator/services/command_cast_result_generator.rb', line 74

def atom?
  serializers&.any? { |s| s == "Foobara::CommandConnectors::Serializers::AtomicSerializer" }
end

#cast_json_result_functionObject



86
87
88
# File 'src/remote_generator/services/command_cast_result_generator.rb', line 86

def cast_json_result_function
  "#{cast_json_result_function_body}\nreturn json"
end

#dependenciesObject



82
83
84
# File 'src/remote_generator/services/command_cast_result_generator.rb', line 82

def dependencies
  nested_model_generators
end

#nested_model_generatorsObject



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'src/remote_generator/services/command_cast_result_generator.rb', line 39

def nested_model_generators
  return @nested_model_generators if defined?(@nested_model_generators)

  nested_model_generators = []

  if result_type.detached_entity? && atom?
    declaration = result_type.is_a?(Manifest::TypeDeclaration) ? result_type.to_type : result_type
    return @nested_model_generators = Set[Services::AtomEntityGenerator.new(declaration)]
  end

  _models_reachable_from_declaration(result_type, initial: true)&.each do |model|
    generator_class = if atom?
                        if model.detached_entity?
                          Services::UnloadedEntityGenerator
                        else
                          Services::AtomModelGenerator
                        end
                      elsif aggregate?
                        Services::AggregateModelGenerator
                      else
                        Services::ModelGenerator
                      end

    new_generator = generator_class.new(model)

    unless nested_model_generators.any? do |g|
      g.relevant_manifest == model && g.class == new_generator.class
    end
      nested_model_generators << new_generator
    end
  end

  @nested_model_generators = nested_model_generators
end

#result_typeObject



23
24
25
# File 'src/remote_generator/services/command_cast_result_generator.rb', line 23

def result_type
  command_manifest.result_type
end

#target_pathObject



27
28
29
# File 'src/remote_generator/services/command_cast_result_generator.rb', line 27

def target_path
  [*scoped_full_path, "castJsonResult.ts"]
end

#template_pathObject



31
32
33
# File 'src/remote_generator/services/command_cast_result_generator.rb', line 31

def template_path
  "Command/castJsonResult.ts.erb"
end