Class: Foobara::RemoteGenerator::Services::ErrorGenerator

Inherits:
TypescriptFromManifestBaseGenerator show all
Defined in:
foobara-typescript-remote-command-generator-0.0.18/src/remote_generator/services/error_generator.rb

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, #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, #templates_dir, #ts_instance_full_name, #ts_instance_full_path, #ts_instance_path, #value_to_ts_value

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::Services::TypescriptFromManifestBaseGenerator

Dynamic Method Handling

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

Instance Method Details

#context_ts_typeObject



43
44
45
46
47
48
49
50
# File 'foobara-typescript-remote-command-generator-0.0.18/src/remote_generator/services/error_generator.rb', line 43

def context_ts_type
  if context_type_declaration.is_a?(Manifest::Attributes) && context_type_declaration.empty?
    # TODO: update other parts of the generator that disable the linting rule to use this instead...
    "Record<string, never>"
  else
    foobara_type_to_ts_type(context_type_declaration, dependency_group:)
  end
end

#context_type_declarationObject



39
40
41
# File 'foobara-typescript-remote-command-generator-0.0.18/src/remote_generator/services/error_generator.rb', line 39

def context_type_declaration
  @context_type_declaration ||= Manifest::TypeDeclaration.new(root_manifest, [*path, :context_type_declaration])
end

#dependenciesObject



52
53
54
# File 'foobara-typescript-remote-command-generator-0.0.18/src/remote_generator/services/error_generator.rb', line 52

def dependencies
  types_depended_on.select { |type| type.detached_entity? || type.custom? || type.model? }
end

#error_base_classObject



26
27
28
29
30
31
32
33
# File 'foobara-typescript-remote-command-generator-0.0.18/src/remote_generator/services/error_generator.rb', line 26

def error_base_class
  case category
  when "data"
    "DataError"
  else
    "RuntimeError"
  end
end

#target_pathObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'foobara-typescript-remote-command-generator-0.0.18/src/remote_generator/services/error_generator.rb', line 9

def target_path
  p = parent

  basename = "#{error_name}.ts".split("::")

  case parent
  when OrganizationGenerator, DomainGenerator, CommandGenerator
    [*p.target_dir, "errors", *basename]
  when nil
    # :nocov:
    raise "Expected #{error_name} to have a parent but it did not"
    # :nocov:
  else
    [*p.target_dir, *basename]
  end
end

#template_pathObject



35
36
37
# File 'foobara-typescript-remote-command-generator-0.0.18/src/remote_generator/services/error_generator.rb', line 35

def template_path
  "Error.ts.erb"
end

#ts_type_full_pathObject



56
57
58
59
60
61
62
63
64
# File 'foobara-typescript-remote-command-generator-0.0.18/src/remote_generator/services/error_generator.rb', line 56

def ts_type_full_path
  if parent.is_a?(CommandGenerator)
    p = super.dup
    p[-2] += "Errors"
    p
  else
    super
  end
end