Class: Orthoses::Outputable::ResolveTypeNames
- Inherits:
-
Object
- Object
- Orthoses::Outputable::ResolveTypeNames
- Includes:
- WriterCopy
- Defined in:
- lib/orthoses/outputable/resolve_type_names.rb
Defined Under Namespace
Modules: WriterCopy
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(loader) ⇒ ResolveTypeNames
constructor
A new instance of ResolveTypeNames.
Methods included from WriterCopy
#name_and_args, #name_and_params
Constructor Details
#initialize(loader) ⇒ ResolveTypeNames
Returns a new instance of ResolveTypeNames.
6 7 8 |
# File 'lib/orthoses/outputable/resolve_type_names.rb', line 6 def initialize(loader) @loader = loader end |
Instance Method Details
#call ⇒ Object
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 |
# File 'lib/orthoses/outputable/resolve_type_names.rb', line 10 def call @loader.call.tap do |store| env = Utils.rbs_environment(cache: false) signatures = store.map do |name, content| buffer = RBS::Buffer.new(content: content.to_rbs, name: "orthoses-resolve_type_names-#{name.downcase}.rbs") decls = [content.to_decl] # Add as known types env.add_signature(buffer: buffer, directives: [], decls: decls) # Will resolve names [buffer, [[], decls]] end.to_h # Reduce resolving names env.signatures.replace(signatures) env = env.resolve_type_names store.each do |name, content| out = StringIO.new writer = RBS::Writer.new(out: out) type_name = RBS::TypeName.parse(content.name).absolute! entry, members = entry_and_members(env, type_name) raise "Cannot fetch entry for #{type_name}" unless entry && members content.header = content_header(entry) members.each do |member| writer.write_member(member) end content.body.replace(out.string.lines) end end end |