Module: Foobara::Types::Type::Concerns::Reflection
Instance Method Summary
collapse
Methods included from Concern
foobara_class_methods_module_for, foobara_concern?, included
Instance Method Details
#deep_types_depended_on ⇒ Object
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
# File 'foobara-0.0.110/projects/types/src/type/concerns/reflection.rb', line 75
def deep_types_depended_on
result = Set.new
to_process = types_depended_on
until to_process.empty?
type = to_process.first
to_process.delete(type)
next if result.include?(type)
result << type
to_process |= type.types_depended_on
end
result.select(&:registered?)
end
|
#inspect ⇒ Object
164
165
166
167
168
169
170
171
172
173
174
|
# File 'foobara-0.0.110/projects/types/src/type/concerns/reflection.rb', line 164
def inspect
name = if scoped_path_set?
scoped_full_name
else
"Anonymous #{base_type.type_symbol}"
end
"#<Type:#{name}:0x#{object_id.to_s(16)} #{declaration_data}>"
end
|
#type_at_path(data_path) ⇒ Object
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
|
# File 'foobara-0.0.110/projects/types/src/type/concerns/reflection.rb', line 93
def type_at_path(data_path)
path_parts = DataPath.for(data_path).path
path_part, *path_parts = path_parts
next_type = case path_part
when :"#"
unless element_type
raise "Expected element_type to be set but is not"
end
element_type
when Symbol
case element_types
when ::Hash
unless element_types.key?(path_part)
raise "Expected element type to have key #{path_part} but does not"
end
element_types[path_part]
when Types::Type
unless element_types.extends?(BuiltinTypes[:attributes])
raise "Expected element type to be a Type but is not"
end
element_types.element_types[path_part]
when nil
raise "Expected element_types to be set but is not"
else
raise "Unsure how to handle path part #{path_part}"
end
when Integer
if extends?(BuiltinTypes[:tuple])
element_types[path_part]
elsif extends?(BuiltinTypes[:array])
element_type
else
raise "Unsure how to handle path part #{path_part}"
end
else
raise "Bad path part #{path_part}"
end
unless next_type
raise "Expected to find a type at #{path_part}"
end
if path_parts.empty?
next_type
else
next_type.type_at_path(path_parts)
end
end
|
#types_depended_on(result = nil) ⇒ Object
as soon as we hit a registered type, don’t go further down that path
9
10
11
12
13
14
15
16
17
18
19
20
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
50
51
52
53
54
55
56
57
58
59
60
61
|
# File 'foobara-0.0.110/projects/types/src/type/concerns/reflection.rb', line 9
def types_depended_on(result = nil)
remove_sensitive = TypeDeclarations.foobara_manifest_context_remove_sensitive?
start = result.nil?
result ||= Set.new
return if result.include?(self)
result << self
return if !start && registered?
to_process = types_to_add_to_manifest
if element_types
to_process += case element_types
when Type
if remove_sensitive && element_types.sensitive?
[]
else
[element_types]
end
when ::Hash
element_types.values.select do |value|
if !remove_sensitive || !value.sensitive?
value.is_a?(Type)
end
end
when ::Array
if remove_sensitive
element_types.reject(&:sensitive?)
else
element_types
end
else
raise "Not sure how to find dependent types for #{element_types}"
end
end
to_process.each do |type|
type.types_depended_on(result)
end
if start
result = result.select { |type| type.registered? && type != self }.to_set
end
result
end
|
#types_to_add_to_manifest ⇒ Object
63
64
65
66
67
68
69
70
71
72
73
|
# File 'foobara-0.0.110/projects/types/src/type/concerns/reflection.rb', line 63
def types_to_add_to_manifest
remove_sensitive = TypeDeclarations.foobara_manifest_context_remove_sensitive?
types = [*base_type, *possible_errors.map(&:error_class)]
if element_type && (!remove_sensitive || !element_type.sensitive?)
types << element_type
end
types
end
|