Class: Spoom::Model
- Inherits:
-
Object
show all
- Extended by:
- T::Sig
- Defined in:
- lib/spoom/model/model.rb,
lib/spoom/model/builder.rb,
lib/spoom/model/reference.rb,
lib/spoom/model/namespace_visitor.rb,
lib/spoom/model/references_visitor.rb
Defined Under Namespace
Classes: Attr, AttrAccessor, AttrReader, AttrWriter, Builder, Class, Constant, Error, Extend, Include, Method, Mixin, Module, Namespace, NamespaceVisitor, Prepend, Property, Reference, ReferencesVisitor, Sig, SingletonClass, Symbol, SymbolDef, UnresolvedSymbol, Visibility
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize ⇒ Model
Returns a new instance of Model.
238
239
240
241
|
# File 'lib/spoom/model/model.rb', line 238
def initialize
@symbols = T.let({}, T::Hash[String, Symbol])
@symbols_hierarchy = T.let(Poset[Symbol].new, Poset[Symbol])
end
|
Instance Attribute Details
#symbols ⇒ Object
Returns the value of attribute symbols.
232
233
234
|
# File 'lib/spoom/model/model.rb', line 232
def symbols
@symbols
end
|
#symbols_hierarchy ⇒ Object
Returns the value of attribute symbols_hierarchy.
235
236
237
|
# File 'lib/spoom/model/model.rb', line 235
def symbols_hierarchy
@symbols_hierarchy
end
|
Instance Method Details
#[](full_name) ⇒ Object
247
248
249
250
251
252
|
# File 'lib/spoom/model/model.rb', line 247
def [](full_name)
symbol = @symbols[full_name]
raise Error, "Symbol not found: #{full_name}" unless symbol
symbol
end
|
#finalize! ⇒ Object
296
297
298
|
# File 'lib/spoom/model/model.rb', line 296
def finalize!
compute_symbols_hierarchy!
end
|
#register_symbol(full_name) ⇒ Object
258
259
260
|
# File 'lib/spoom/model/model.rb', line 258
def register_symbol(full_name)
@symbols[full_name] ||= Symbol.new(full_name)
end
|
#resolve_symbol(full_name, context:) ⇒ Object
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
|
# File 'lib/spoom/model/model.rb', line 263
def resolve_symbol(full_name, context:)
if full_name.start_with?("::")
full_name = full_name.delete_prefix("::")
return @symbols[full_name] ||= UnresolvedSymbol.new(full_name)
end
target = T.let(@symbols[full_name], T.nilable(Symbol))
return target if target
parts = context.full_name.split("::")
until parts.empty?
target = @symbols["#{parts.join("::")}::#{full_name}"]
return target if target
parts.pop
end
@symbols[full_name] = UnresolvedSymbol.new(full_name)
end
|
#subtypes(symbol) ⇒ Object
290
291
292
293
|
# File 'lib/spoom/model/model.rb', line 290
def subtypes(symbol)
poe = @symbols_hierarchy[symbol]
poe.descendants
end
|
#supertypes(symbol) ⇒ Object
284
285
286
287
|
# File 'lib/spoom/model/model.rb', line 284
def supertypes(symbol)
poe = @symbols_hierarchy[symbol]
poe.ancestors
end
|