Class: TypeProf::RBSReader
Relationships & Source Files | |
Inherits: | Object |
Defined in: | lib/typeprof/import.rb |
Class Method Summary
Instance Method Summary
Constructor Details
.new ⇒ RBSReader
# File 'lib/typeprof/import.rb', line 5
def initialize @repo = RBS::Repository.new Config.gem_repo_dirs.each do |dir| @repo.add(Pathname(dir)) end @env, @builtin_env_json = RBSReader.get_builtin_env end
Class Method Details
.get_builtin_env
[ GitHub ]# File 'lib/typeprof/import.rb', line 14
def self.get_builtin_env unless @builtin_env @builtin_env = RBS::Environment.new loader = RBS::EnvironmentLoader.new(repository: @repo) new_decls = loader.load(env: @builtin_env).map {|decl,| decl } @builtin_env_json = load_rbs(@builtin_env, new_decls) end return @builtin_env.dup, @builtin_env_json end
.load_rbs(env, new_decls)
[ GitHub ]# File 'lib/typeprof/import.rb', line 69
def self.load_rbs(env, new_decls) all_env = env.resolve_type_names resolver = RBS::TypeNameResolver.from_env(all_env) cur_env = RBS::Environment.new new_decls.each do |decl| cur_env << env.resolve_declaration(resolver, decl, outer: [], prefix: RBS::Namespace.root) end RBS2JSON.new(all_env, cur_env).dump_json end
Instance Method Details
#load_builtin
[ GitHub ]# File 'lib/typeprof/import.rb', line 26
def load_builtin @builtin_env_json end
#load_library(lib)
[ GitHub ]# File 'lib/typeprof/import.rb', line 30
def load_library(lib) loader = RBS::EnvironmentLoader.new(core_root: nil, repository: @repo) loader.add(library: lib) case lib when 'bigdecimal-math' loader.add(library: 'bigdecimal') when "yaml" loader.add(library: "pstore") loader.add(library: "dbm") when "logger" loader.add(library: "monitor") when "csv" loader.add(library: "forwardable") when "prime" loader.add(library: "singleton") end new_decls = loader.load(env: @env).map {|decl,| decl } RBSReader.load_rbs(@env, new_decls) end