class TypeProf::RBSReader

Public Class Methods

get_builtin_env() click to toggle source
# File typeprof-0.15.2/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) click to toggle source
# File typeprof-0.15.2/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
new() click to toggle source
# File typeprof-0.15.2/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

Public Instance Methods

load_builtin() click to toggle source
# File typeprof-0.15.2/lib/typeprof/import.rb, line 26
def load_builtin
  @builtin_env_json
end
load_library(lib) click to toggle source
# File typeprof-0.15.2/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
load_paths(paths) click to toggle source
# File typeprof-0.15.2/lib/typeprof/import.rb, line 52
def load_paths(paths)
  loader = RBS::EnvironmentLoader.new(core_root: nil, repository: @repo)
  paths.each {|path| loader.add(path: path) }
  new_decls = loader.load(env: @env).map {|decl,| decl }
  RBSReader.load_rbs(@env, new_decls)
end
load_rbs_string(name, content) click to toggle source
# File typeprof-0.15.2/lib/typeprof/import.rb, line 59
def load_rbs_string(name, content)
  buffer = RBS::Buffer.new(name: name, content: content)
  new_decls = []
  RBS::Parser.parse_signature(buffer).each do |decl|
    @env << decl
    new_decls << decl
  end
  RBSReader.load_rbs(@env, new_decls)
end