Class: Foobara::RemoteGenerator::Services::TypeGenerator
Constant Summary
TruncatedInspect::MAX_LENGTH
Instance Attribute Summary
#belongs_to_dependency_group, #relevant_manifest
Class Method Summary
collapse
Instance Method Summary
collapse
#==, #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
#==, #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
#inspect, truncating
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
in the class Foobara::FilesGenerator
Class Method Details
.lru_cache ⇒ Object
8
9
10
|
# File 'src/remote_generator/services/type_generator.rb', line 8
def lru_cache
@lru_cache ||= LruCache.new(1000)
end
|
.new(relevant_manifest) ⇒ Object
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
# File 'src/remote_generator/services/type_generator.rb', line 12
def new(relevant_manifest)
unless self == TypeGenerator
generator = lru_cache.cached([self, relevant_manifest]) do
super
end
return generator
end
if relevant_manifest.detached_entity?
EntityGenerator.new(relevant_manifest)
elsif relevant_manifest.model?
ModelGenerator.new(relevant_manifest)
else
lru_cache.cached([self, relevant_manifest]) do
super
end
end
end
|
Instance Method Details
#aggregate_attributes_ts_type ⇒ Object
139
140
141
142
143
144
145
146
|
# File 'src/remote_generator/services/type_generator.rb', line 139
def aggregate_attributes_ts_type
association_depth = AssociationDepth::AGGREGATE
foobara_type_to_ts_type(attributes_type,
association_depth:,
dependency_group:,
is_output: true,
parent: relevant_manifest)
end
|
#atom_attributes_ts_type ⇒ Object
130
131
132
133
134
135
136
137
|
# File 'src/remote_generator/services/type_generator.rb', line 130
def atom_attributes_ts_type
association_depth = AssociationDepth::ATOM
foobara_type_to_ts_type(attributes_type,
association_depth:,
dependency_group:,
is_output: true,
parent: relevant_manifest)
end
|
#attribute_names ⇒ Object
148
149
150
|
# File 'src/remote_generator/services/type_generator.rb', line 148
def attribute_names
attributes_type.attribute_names
end
|
#attributes_type_ts_type ⇒ Object
121
122
123
124
125
126
127
128
|
# File 'src/remote_generator/services/type_generator.rb', line 121
def attributes_type_ts_type
association_depth = AssociationDepth::AMBIGUOUS
foobara_type_to_ts_type(attributes_type,
association_depth:,
dependency_group:,
is_output: true,
parent: relevant_manifest)
end
|
#custom_type_generators ⇒ Object
107
108
109
110
111
|
# File 'src/remote_generator/services/type_generator.rb', line 107
def custom_type_generators
@custom_type_generators ||= types_depended_on.reject(&:builtin?).reject(&:model?).map do |type|
Services::TypeGenerator.new(type)
end
end
|
#dependencies ⇒ Object
113
114
115
|
# File 'src/remote_generator/services/type_generator.rb', line 113
def dependencies
@dependencies ||= custom_type_generators + model_generators
end
|
#model_generators ⇒ Object
101
102
103
104
105
|
# File 'src/remote_generator/services/type_generator.rb', line 101
def model_generators
@model_generators ||= types_depended_on.select(&:model?).reject(&:builtin?).map do |model|
Services::ModelGenerator.new(model)
end
end
|
#scoped_full_path(points = nil) ⇒ Object
61
62
63
64
65
66
67
68
69
70
|
# File 'src/remote_generator/services/type_generator.rb', line 61
def scoped_full_path(points = nil)
full_path = type_manifest.scoped_full_path
if points
start_at = full_path.size - points - 1
full_path[start_at..]
else
full_path
end
end
|
#target_path ⇒ Object
35
36
37
|
# File 'src/remote_generator/services/type_generator.rb', line 35
def target_path
[*domain.scoped_full_path, "Types", *type_prefix, "#{type_short_name}.ts"]
end
|
#template_path ⇒ Object
43
44
45
|
# File 'src/remote_generator/services/type_generator.rb', line 43
def template_path
["Type", "Type.ts.erb"]
end
|
#type_guts ⇒ Object
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
|
# File 'src/remote_generator/services/type_generator.rb', line 80
def type_guts
guts = if declaration_data.key?("one_of")
declaration_data["one_of"].map do |enum_item|
value_to_ts_value(enum_item)
end.join(" | ")
else
raise "Haven't implemented other types yet"
end
if declaration_data["allow_nil"]
guts += " | undefined"
end
guts
end
|
#type_name(points = nil) ⇒ Object
72
73
74
75
76
77
78
|
# File 'src/remote_generator/services/type_generator.rb', line 72
def type_name(points = nil)
if points
scoped_full_path(points).join(".")
else
scoped_path.join(".")
end
end
|
#type_name_downcase ⇒ Object
117
118
119
|
# File 'src/remote_generator/services/type_generator.rb', line 117
def type_name_downcase
type_short_name[0].downcase + type_short_name[1..]
end
|
#type_prefix ⇒ Object
47
48
49
50
51
52
53
54
55
56
57
58
59
|
# File 'src/remote_generator/services/type_generator.rb', line 47
def type_prefix
path = scoped_prefix
if path && !path.empty?
if path.first == "Types"
path[1..]
else
path
end
else
[]
end
end
|
#type_short_name ⇒ Object
39
40
41
|
# File 'src/remote_generator/services/type_generator.rb', line 39
def type_short_name
scoped_short_name
end
|