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 ⇒ Object
- .load(*path) ⇒ Array<Solargraph::Pin::Base>?
- .save(*path, pins) ⇒ Boolean
-
.work_dir ⇒ String
The working directory for the current Ruby and Solargraph versions.
Class Method Details
.base_dir ⇒ String
The base directory where cached documentation is installed.
9 10 11 12 13 14 15 |
# 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 ⇒ Object
48 49 50 |
# File 'lib/solargraph/cache.rb', line 48 def clear FileUtils.rm_rf base_dir, secure: true end |
.load(*path) ⇒ Array<Solargraph::Pin::Base>?
27 28 29 30 31 32 33 34 35 |
# 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.}" FileUtils.rm_f file nil end |
.save(*path, pins) ⇒ Boolean
38 39 40 41 42 43 44 45 46 |
# 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 ⇒ String
The working directory for the current Ruby and Solargraph versions.
20 21 22 23 24 |
# 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 |