module Solargraph::PinCache
Public Class Methods
Source
# File lib/solargraph/pin_cache.rb, line 13 def base_dir # The directory is not stored in a variable so it can be overridden # in specs. ENV['SOLARGRAPH_CACHE'] || (ENV['XDG_CACHE_HOME'] ? File.join(ENV['XDG_CACHE_HOME'], 'solargraph') : nil) || File.join(Dir.home, '.cache', 'solargraph') end
The base directory where cached YARD documentation and serialized pins are serialized
@return [String]
Source
# File lib/solargraph/pin_cache.rb, line 188 def clear FileUtils.rm_rf base_dir, secure: true end
@return [void]
Source
# File lib/solargraph/pin_cache.rb, line 135 def combined_path(gemspec, hash) File.join(work_dir, 'combined', "#{gemspec.name}-#{gemspec.version}-#{hash || 0}.ser") end
@param gemspec [Gem::Specification] @param hash [String, nil] @return [String]
Source
# File lib/solargraph/pin_cache.rb, line 141 def combined_path_prefix(gemspec) File.join(work_dir, 'combined', "#{gemspec.name}-#{gemspec.version}-") end
@param gemspec [Gem::Specification] @return [String]
Source
# File lib/solargraph/pin_cache.rb, line 64 def core_path File.join(work_dir, 'core.ser') end
@return [String]
Source
# File lib/solargraph/pin_cache.rb, line 156 def deserialize_combined_gem gemspec, hash load(combined_path(gemspec, hash)) end
@param gemspec [Gem::Specification] @param hash [String, nil] @return [Array<Pin::Base>, nil]
Source
# File lib/solargraph/pin_cache.rb, line 69 def deserialize_core load(core_path) end
@return [Array<Pin::Base>, nil]
Source
# File lib/solargraph/pin_cache.rb, line 120 def deserialize_rbs_collection_gem(gemspec, hash) load(rbs_collection_path(gemspec, hash)) end
@param gemspec [Gem::Specification] @param hash [String, nil] @return [Array<Pin::Base>, nil]
Source
# File lib/solargraph/pin_cache.rb, line 52 def deserialize_stdlib_require require load(stdlib_require_path(require)) end
@param require [String] @return [Array<Pin::Base>, nil]
Source
# File lib/solargraph/pin_cache.rb, line 87 def deserialize_yard_gem(gemspec) load(yard_gem_path(gemspec)) end
@param gemspec [Gem::Specification] @return [Array<Pin::Base>, nil]
Source
# File lib/solargraph/pin_cache.rb, line 163 def has_rbs_collection?(gemspec, hash) exist?(rbs_collection_path(gemspec, hash)) end
@param gemspec [Gem::Specification] @param hash [String, nil] @return [Boolean]
Source
# File lib/solargraph/pin_cache.rb, line 100 def has_yard?(gemspec) exist?(yard_gem_path(gemspec)) end
@param gemspec [Gem::Specification] @return [Boolean]
Source
# File lib/solargraph/pin_cache.rb, line 107 def rbs_collection_path(gemspec, hash) File.join(work_dir, 'rbs', "#{gemspec.name}-#{gemspec.version}-#{hash || 0}.ser") end
@param gemspec [Gem::Specification] @param hash [String, nil] @return [String]
Source
# File lib/solargraph/pin_cache.rb, line 113 def rbs_collection_path_prefix(gemspec) File.join(work_dir, 'rbs', "#{gemspec.name}-#{gemspec.version}-") end
@param gemspec [Gem::Specification] @return [String]
Source
# File lib/solargraph/pin_cache.rb, line 149 def serialize_combined_gem(gemspec, hash, pins) save(combined_path(gemspec, hash), pins) end
@param gemspec [Gem::Specification] @param hash [String, nil] @param pins [Array<Pin::Base>] @return [void]
Source
# File lib/solargraph/pin_cache.rb, line 75 def serialize_core pins save(core_path, pins) end
@param pins [Array<Pin::Base>] @return [void]
Source
# File lib/solargraph/pin_cache.rb, line 128 def serialize_rbs_collection_gem(gemspec, hash, pins) save(rbs_collection_path(gemspec, hash), pins) end
@param gemspec [Gem::Specification] @param hash [String, nil] @param pins [Array<Pin::Base>]n @return [void]
Source
# File lib/solargraph/pin_cache.rb, line 59 def serialize_stdlib_require require, pins save(stdlib_require_path(require), pins) end
@param require [String] @param pins [Array<Pin::Base>] @return [void]
Source
# File lib/solargraph/pin_cache.rb, line 94 def serialize_yard_gem(gemspec, pins) save(yard_gem_path(gemspec), pins) end
@param gemspec [Gem::Specification] @param pins [Array<Pin::Base>] @return [void]
Source
# File lib/solargraph/pin_cache.rb, line 40 def stdlib_path File.join(work_dir, 'stdlib') end
@return [String]
Source
# File lib/solargraph/pin_cache.rb, line 46 def stdlib_require_path require File.join(stdlib_path, "#{require}.ser") end
@param require [String] @return [String]
Source
# File lib/solargraph/pin_cache.rb, line 168 def uncache_core uncache(core_path) end
@return [void]
Source
# File lib/solargraph/pin_cache.rb, line 180 def uncache_gem(gemspec, out: nil) uncache(yardoc_path(gemspec), out: out) uncache_by_prefix(rbs_collection_path_prefix(gemspec), out: out) uncache(yard_gem_path(gemspec), out: out) uncache_by_prefix(combined_path_prefix(gemspec), out: out) end
@param gemspec [Gem::Specification] @param out [IO, nil] @return [void]
Source
# File lib/solargraph/pin_cache.rb, line 173 def uncache_stdlib uncache(stdlib_path) end
@return [void]
Source
# File lib/solargraph/pin_cache.rb, line 24 def work_dir # The directory is not stored in a variable so it can be overridden # in specs. File.join(base_dir, "ruby-#{RUBY_VERSION}", "rbs-#{RBS::VERSION}", "solargraph-#{Solargraph::VERSION}") end
The working directory for the current Ruby, RBS, and Solargraph versions.
@return [String]
Source
# File lib/solargraph/pin_cache.rb, line 81 def yard_gem_path gemspec File.join(work_dir, 'yard', "#{gemspec.name}-#{gemspec.version}.ser") end
@param gemspec [Gem::Specification] @return [String]
Source
# File lib/solargraph/pin_cache.rb, line 32 def yardoc_path gemspec File.join(base_dir, "yard-#{YARD::VERSION}", "yard-activesupport-concern-#{YARD::ActiveSupport::Concern::VERSION}", "#{gemspec.name}-#{gemspec.version}.yardoc") end
@param gemspec [Gem::Specification] @return [String]
Private Class Methods
Source
# File lib/solargraph/pin_cache.rb, line 206 def exist? *path File.file? File.join(*path) end
@param path [String]
Source
# File lib/solargraph/pin_cache.rb, line 196 def load file return nil unless File.file?(file) Marshal.load(File.read(file, mode: 'rb')) rescue StandardError => e Solargraph.logger.warn "Failed to load cached file #{file}: [#{e.class}] #{e.message}" FileUtils.rm_f file nil end
@param file [String] @return [Array<Solargraph::Pin::Base>, nil]
Source
# File lib/solargraph/pin_cache.rb, line 213 def save file, pins base = File.dirname(file) FileUtils.mkdir_p base unless File.directory?(base) ser = Marshal.dump(pins) File.write file, ser, mode: 'wb' logger.debug { "Cache#save: Saved #{pins.length} pins to #{file}" } end
@param file [String] @param pins [Array<Pin::Base>] @return [void]
Source
# File lib/solargraph/pin_cache.rb, line 223 def uncache *path_segments, out: nil path = File.join(*path_segments) if File.exist?(path) FileUtils.rm_rf path, secure: true out.puts "Clearing pin cache in #{path}" unless out.nil? end end
@param path_segments [Array<String>] @return [void]
Source
# File lib/solargraph/pin_cache.rb, line 233 def uncache_by_prefix *path_segments, out: nil path = File.join(*path_segments) glob = "#{path}*" out.puts "Clearing pin cache in #{glob}" unless out.nil? Dir.glob(glob).each do |file| next unless File.file?(file) FileUtils.rm_rf file, secure: true out.puts "Clearing pin cache in #{file}" unless out.nil? end end
@return [void] @param path_segments [Array<String>]