Class: Solargraph::RbsMap
- Inherits:
-
Object
- Object
- Solargraph::RbsMap
- Includes:
- Logging
- 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
Defined Under Namespace
Modules: CoreFills Classes: Conversions, CoreMap, StdlibMap
Constant Summary collapse
- @@rbs_maps_hash =
{}
Constants included from Logging
Logging::DEFAULT_LOG_LEVEL, Logging::LOG_LEVELS
Instance Attribute Summary collapse
-
#library ⇒ Object
readonly
Returns the value of attribute library.
-
#rbs_collection_config_path ⇒ Object
readonly
Returns the value of attribute rbs_collection_config_path.
-
#rbs_collection_paths ⇒ Object
readonly
Returns the value of attribute rbs_collection_paths.
Class Method Summary collapse
- .from_gemspec(gemspec, rbs_collection_path, rbs_collection_config_path) ⇒ RbsMap
- .load(library) ⇒ RbsMap
Instance Method Summary collapse
-
#cache_key ⇒ String
Representing the version of the RBS info fetched for the given library.
-
#initialize(library, version = nil, rbs_collection_config_path: nil, rbs_collection_paths: []) ⇒ RbsMap
constructor
A new instance of RbsMap.
- #path_pin(path, klass = Pin::Base) ⇒ generic<T>?
- #path_pins(path) ⇒ Array<Pin::Base>
- #pins ⇒ Array<Pin::Base>
- #repository ⇒ RBS::Repository
- #resolved? ⇒ Boolean
Methods included from Logging
Constructor Details
#initialize(library, version = nil, rbs_collection_config_path: nil, rbs_collection_paths: []) ⇒ RbsMap
Returns a new instance of RbsMap.
29 30 31 32 33 34 35 36 37 38 |
# File 'lib/solargraph/rbs_map.rb', line 29 def initialize library, version = nil, rbs_collection_config_path: nil, rbs_collection_paths: [] if rbs_collection_config_path.nil? && !rbs_collection_paths.empty? raise 'Please provide rbs_collection_config_path if you provide rbs_collection_paths' end @library = library @version = version @rbs_collection_config_path = rbs_collection_config_path @rbs_collection_paths = rbs_collection_paths add_library loader, library, version end |
Instance Attribute Details
#library ⇒ Object (readonly)
Returns the value of attribute library.
19 20 21 |
# File 'lib/solargraph/rbs_map.rb', line 19 def library @library end |
#rbs_collection_config_path ⇒ Object (readonly)
Returns the value of attribute rbs_collection_config_path.
23 24 25 |
# File 'lib/solargraph/rbs_map.rb', line 23 def rbs_collection_config_path @rbs_collection_config_path end |
#rbs_collection_paths ⇒ Object (readonly)
Returns the value of attribute rbs_collection_paths.
21 22 23 |
# File 'lib/solargraph/rbs_map.rb', line 21 def rbs_collection_paths @rbs_collection_paths end |
Class Method Details
.from_gemspec(gemspec, rbs_collection_path, rbs_collection_config_path) ⇒ RbsMap
79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/solargraph/rbs_map.rb', line 79 def self.from_gemspec gemspec, rbs_collection_path, rbs_collection_config_path rbs_map = RbsMap.new(gemspec.name, gemspec.version, rbs_collection_paths: [rbs_collection_path].compact, rbs_collection_config_path: rbs_collection_config_path) return rbs_map if rbs_map.resolved? # try any version of the gem in the collection RbsMap.new(gemspec.name, nil, rbs_collection_paths: [rbs_collection_path].compact, rbs_collection_config_path: rbs_collection_config_path) end |
Instance Method Details
#cache_key ⇒ String
Returns representing the version of the RBS info fetched for the given library. Must change when the RBS info is updated upstream for the same library and version. May change if the config for where information comes form changes.
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/solargraph/rbs_map.rb', line 49 def cache_key @hextdigest ||= begin # @type [String, nil] data = nil if rbs_collection_config_path lockfile_path = RBS::Collection::Config.to_lockfile_path(Pathname.new(rbs_collection_config_path)) if lockfile_path.exist? collection_config = RBS::Collection::Config.from_path lockfile_path gem_config = collection_config.gem(library) data = gem_config&.to_s end end if data.nil? || data.empty? if resolved? # definitely came from the gem itself and not elsewhere - # only one version per gem 'gem-export' else 'unresolved' end else Digest::SHA1.hexdigest(data) end end end |
#path_pin(path, klass = Pin::Base) ⇒ generic<T>?
100 101 102 103 |
# File 'lib/solargraph/rbs_map.rb', line 100 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>
107 108 109 |
# File 'lib/solargraph/rbs_map.rb', line 107 def path_pins path pins.select { |p| p.path == path } end |
#pins ⇒ Array<Pin::Base>
92 93 94 |
# File 'lib/solargraph/rbs_map.rb', line 92 def pins @pins ||= resolved? ? conversions.pins : [] end |
#repository ⇒ RBS::Repository
116 117 118 119 120 121 122 123 |
# File 'lib/solargraph/rbs_map.rb', line 116 def repository @repository ||= RBS::Repository.new(no_stdlib: false).tap do |repo| @rbs_collection_paths.each do |dir| dir_path = Pathname.new(dir) repo.add(dir_path) if dir_path.exist? && dir_path.directory? end end end |
#resolved? ⇒ Boolean
111 112 113 |
# File 'lib/solargraph/rbs_map.rb', line 111 def resolved? @resolved end |