Module: Solargraph::Cache
- Defined in:
- lib/solargraph/cache.rb
Class Method Summary collapse
-
.base_dir ⇒ String
The base directory where cached documentation is installed.
- .clear ⇒ void
- .exist?(*path) ⇒ Boolean
-
.join(*path) ⇒ String
Append the given path to the current cache directory (‘work_dir`).
- .load(*path) ⇒ Array<Solargraph::Pin::Base>?
- .save(*path, pins) ⇒ void
- .uncache(*path) ⇒ void
-
.work_dir ⇒ String
The working directory for the current Ruby, RBS, and Solargraph versions.
Class Method Details
.base_dir ⇒ String
The base directory where cached documentation is installed.
10 11 12 13 14 15 16 |
# File 'lib/solargraph/cache.rb', line 10 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 |
.clear ⇒ void
This method returns an undefined value.
72 73 74 |
# File 'lib/solargraph/cache.rb', line 72 def clear FileUtils.rm_rf base_dir, secure: true end |
.exist?(*path) ⇒ Boolean
50 51 52 |
# File 'lib/solargraph/cache.rb', line 50 def exist? *path File.file? join(*path) end |
.join(*path) ⇒ String
Append the given path to the current cache directory (‘work_dir`).
34 35 36 |
# File 'lib/solargraph/cache.rb', line 34 def join *path File.join(work_dir, *path) end |
.load(*path) ⇒ Array<Solargraph::Pin::Base>?
40 41 42 43 44 45 46 47 48 |
# File 'lib/solargraph/cache.rb', line 40 def load *path file = join(*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.}" FileUtils.rm_f file nil end |
.save(*path, pins) ⇒ void
This method returns an undefined value.
57 58 59 60 61 62 63 |
# File 'lib/solargraph/cache.rb', line 57 def save *path, pins 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' end |
.uncache(*path) ⇒ void
This method returns an undefined value.
67 68 69 |
# File 'lib/solargraph/cache.rb', line 67 def uncache *path FileUtils.rm_rf File.join(work_dir, *path), secure: true end |
.work_dir ⇒ String
The working directory for the current Ruby, RBS, and Solargraph versions.
21 22 23 24 25 |
# File 'lib/solargraph/cache.rb', line 21 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 |