Class: Solargraph::RbsMap

Inherits:
Object
  • Object
show all
Includes:
Conversions
Defined in:
lib/solargraph/rbs_map.rb,
lib/solargraph/rbs_map/core_map.rb,
lib/solargraph/rbs_map/core_fills.rb,
lib/solargraph/rbs_map/stdlib_map.rb,
lib/solargraph/rbs_map/conversions.rb

Direct Known Subclasses

StdlibMap

Defined Under Namespace

Modules: Conversions, CoreFills Classes: CoreMap, StdlibMap

Constant Summary collapse

@@rbs_maps_hash =
{}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Conversions

#pins

Constructor Details

#initialize(library, version = nil, directories: []) ⇒ RbsMap

Returns a new instance of RbsMap.

Parameters:

  • library (String)
  • version (String, nil) (defaults to: nil)
  • directories (Array<Pathname, String>) (defaults to: [])


23
24
25
26
27
28
29
30
31
32
# File 'lib/solargraph/rbs_map.rb', line 23

def initialize library, version = nil, directories: []
  @library = library
  @version = version
  @collection = nil
  @directories = directories
  loader = RBS::EnvironmentLoader.new(core_root: nil, repository: repository)
  add_library loader, library, version
  return unless resolved?
  load_environment_to_pins(loader)
end

Instance Attribute Details

#libraryObject (readonly)

Returns the value of attribute library.



18
19
20
# File 'lib/solargraph/rbs_map.rb', line 18

def library
  @library
end

Class Method Details

.from_gemspec(gemspec) ⇒ Object

Parameters:

  • gemspec (Gem::Specification)


68
69
70
# File 'lib/solargraph/rbs_map.rb', line 68

def self.from_gemspec(gemspec)
  RbsMap.new(gemspec.name, gemspec.version)
end

.load(library) ⇒ RbsMap

Parameters:

  • library (String)

Returns:



63
64
65
# File 'lib/solargraph/rbs_map.rb', line 63

def self.load library
  @@rbs_maps_hash[library] ||= RbsMap.new(library)
end

Instance Method Details

#path_pin(path, klass = Pin::Base) ⇒ generic<T>?

Parameters:

  • path (String)
  • klass (Class<generic<T>>) (defaults to: Pin::Base)

Returns:

  • (generic<T>, nil)


38
39
40
41
# File 'lib/solargraph/rbs_map.rb', line 38

def path_pin path, klass = Pin::Base
  pin = pins.find { |p| p.path == path }
  pin if pin&.is_a?(klass)
end

#path_pins(path) ⇒ Array<Pin::Base>

Parameters:

  • path (String)

Returns:



45
46
47
# File 'lib/solargraph/rbs_map.rb', line 45

def path_pins path
  pins.select { |p| p.path == path }
end

#repositoryObject



53
54
55
56
57
58
59
# File 'lib/solargraph/rbs_map.rb', line 53

def repository
  @repository ||= RBS::Repository.new(no_stdlib: false).tap do |repo|
    # @todo Temporarily ignoring external directories due to issues with
    #   incomplete/broken gem_rbs_collection installations
    # @directories.each { |dir| repo.add(Pathname.new(dir)) }
  end
end

#resolved?Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/solargraph/rbs_map.rb', line 49

def resolved?
  @resolved
end