Class: RBS::Environment::UseMap
- Inherits:
-
Object
- Object
- RBS::Environment::UseMap
- Defined in:
- lib/rbs/environment/use_map.rb
Defined Under Namespace
Classes: Table
Instance Attribute Summary collapse
-
#use_dirs ⇒ Object
readonly
Returns the value of attribute use_dirs.
Instance Method Summary collapse
- #build_map(clause) ⇒ Object
-
#initialize(table:) ⇒ UseMap
constructor
A new instance of UseMap.
- #resolve(type_name) ⇒ Object
- #resolve?(type_name) ⇒ Boolean
Constructor Details
#initialize(table:) ⇒ UseMap
Returns a new instance of UseMap.
30 31 32 33 34 |
# File 'lib/rbs/environment/use_map.rb', line 30 def initialize(table:) @use_dirs = [] @map = {} @table = table end |
Instance Attribute Details
#use_dirs ⇒ Object (readonly)
Returns the value of attribute use_dirs.
28 29 30 |
# File 'lib/rbs/environment/use_map.rb', line 28 def use_dirs @use_dirs end |
Instance Method Details
#build_map(clause) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/rbs/environment/use_map.rb', line 36 def build_map(clause) case clause when AST::Directives::Use::SingleClause if clause.new_name @map[clause.new_name] = clause.type_name.absolute! else @map[clause.type_name.name] = clause.type_name.absolute! end when AST::Directives::Use::WildcardClause @table.children.fetch(clause.namespace.absolute!).each do |child| @map[child.name] = child end end self end |
#resolve(type_name) ⇒ Object
72 73 74 |
# File 'lib/rbs/environment/use_map.rb', line 72 def resolve(type_name) resolve?(type_name) || type_name end |
#resolve?(type_name) ⇒ Boolean
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/rbs/environment/use_map.rb', line 53 def resolve?(type_name) return if type_name.absolute? hd, *tl = type_name.namespace.path if hd # namespace is not empty if tn = @map[hd] path = [*tn.namespace.path, tn.name, *tl] TypeName.new( namespace: Namespace.new(absolute: true, path: path), name: type_name.name ) end else @map[type_name.name] end end |