module Solargraph::Cache
Public Class Methods
base_dir()
click to toggle source
The base directory where cached documentation is installed.
@return [String]
# File lib/solargraph/cache.rb, line 9 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') : File.join(Dir.home, '.cache', 'solargraph') end
clear()
click to toggle source
# File lib/solargraph/cache.rb, line 48 def clear FileUtils.rm_rf base_dir, secure: true end
load(*path)
click to toggle source
@return [Array<Solargraph::Pin::Base>, nil]
# File lib/solargraph/cache.rb, line 27 def load *path file = File.join(work_dir, *path) 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
save(*path, pins)
click to toggle source
@return [Boolean]
# File lib/solargraph/cache.rb, line 38 def save *path, pins return false if pins.empty? file = File.join(work_dir, *path) base = File.dirname(file) FileUtils.mkdir_p base unless File.directory?(base) ser = Marshal.dump(pins) File.write file, ser, mode: 'wb' true end
work_dir()
click to toggle source
The working directory for the current Ruby and Solargraph versions.
@return [String]
# File lib/solargraph/cache.rb, line 20 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