Class: Foobara::RemoteGenerator::Generators::DomainGenerator

Inherits:
TypescriptFromManifestBaseGenerator show all
Defined in:
foobara-typescript-remote-command-generator-1.3.1/src/generators/domain_generator.rb

Direct Known Subclasses

DomainConfigGenerator

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 TypescriptFromManifestBaseGenerator

#==, #attributes_to_ts_type, #auto_dirty_queries?, #collision_winners, #custom_type_to_ts_type_name, #dependency_group, #dependency_roots, #foobara_type_to_ts_type, #hash, #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, #value_to_ts_value, #will_define

Methods inherited from FilesGenerator

#==, #absolute_template_path, #applicable?, #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::Generators::TypescriptFromManifestBaseGenerator

Dynamic Method Handling

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

Instance Method Details

#all_type_generatorsObject



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'src/generators/domain_generator.rb', line 59

def all_type_generators
  all_type_generators = []

  generators_allowed_for_inputs = [*type_generators, *model_generators]
  generators_allowed_for_errors_or_result = [*generators_allowed_for_inputs, *detached_entity_generators]

  Manifest::RootManifest.new(root_manifest).commands.each do |command_manifest|
    command_generator = CommandGenerator.new(command_manifest)

    command_generator.inputs_types_depended_on.each do |type_manifest|
      next unless type_manifest.domain == relevant_manifest

      generators_allowed_for_inputs.each do |generator|
        if generator.relevant_manifest == type_manifest
          all_type_generators << generator
        end
      end
    end

    [
      *command_generator.result_type&.to_type,
      *command_generator.result_types_depended_on.each,
      *command_generator.errors_types_depended_on
    ].each do |type_manifest|
      next unless type_manifest.domain == relevant_manifest

      generators_allowed_for_errors_or_result.each do |generator|
        if generator.relevant_manifest == type_manifest
          all_type_generators << generator
        end
      end
    end
  end

  all_type_generators.uniq!
  all_type_generators
end

#command_generatorsObject



25
26
27
28
29
# File 'src/generators/domain_generator.rb', line 25

def command_generators
  @command_generators ||= domain_manifest.commands.map do |command_manifest|
    generator_for(command_manifest)
  end
end

#dependenciesObject



97
98
99
# File 'src/generators/domain_generator.rb', line 97

def dependencies
  @dependencies ||= [*command_generators, *all_type_generators, organization]
end

#detached_entity_generatorsObject



31
32
33
34
35
# File 'src/generators/domain_generator.rb', line 31

def detached_entity_generators
  @detached_entity_generators ||= domain_manifest.detached_entities.flat_map do |entity_manifest|
    EntityVariantsGenerator.new(entity_manifest).dependencies.to_a
  end
end

#domain_nameObject



101
102
103
# File 'src/generators/domain_generator.rb', line 101

def domain_name
  scoped_name || "GlobalDomain"
end

#import_destructureObject



9
10
11
# File 'src/generators/domain_generator.rb', line 9

def import_destructure
  "* as #{domain_name}"
end

#model_generatorsObject



49
50
51
52
53
54
55
56
57
# File 'src/generators/domain_generator.rb', line 49

def model_generators
  @model_generators ||= begin
    only_models = domain_manifest.models.reject(&:detached_entity?)

    only_models.flat_map do |model_manifest|
      ModelVariantsGenerator.new(model_manifest).dependencies.to_a
    end
  end
end

#organization_generatorObject



105
106
107
# File 'src/generators/domain_generator.rb', line 105

def organization_generator
  @organization_generator ||= OrganizationGenerator.new(domain_manifest.organization)
end

#organization_nameObject



109
# File 'src/generators/domain_generator.rb', line 109

def organization_name = organization_generator.organization_name

#target_pathObject



13
14
15
16
17
18
19
# File 'src/generators/domain_generator.rb', line 13

def target_path
  if global?
    ["GlobalDomain", "index.ts"]
  else
    [*scoped_full_path, "index.ts"]
  end
end

#template_pathObject



21
22
23
# File 'src/generators/domain_generator.rb', line 21

def template_path
  "Domain.ts.erb"
end

#type_generatorsObject



37
38
39
40
41
42
43
44
45
46
47
# File 'src/generators/domain_generator.rb', line 37

def type_generators
  @type_generators ||= begin
    # TODO: create a Manifest::Domain#custom_types
    only_custom_types = domain_manifest.types.reject(&:model?)
    only_custom_types.reject!(&:builtin?)

    only_custom_types.map do |type|
      TypeGenerator.new(type)
    end
  end
end