Module: Solargraph::PinCache
- Extended by:
- Logging
- Defined in:
- lib/solargraph/pin_cache.rb
Constant Summary
Constants included
from Logging
Logging::DEFAULT_LOG_LEVEL, Logging::LOG_LEVELS
Class Method Summary
collapse
-
.base_dir ⇒ String
The base directory where cached YARD documentation and serialized pins are serialized.
-
.clear ⇒ void
-
.combined_path(gemspec, hash) ⇒ Object
-
.combined_path_prefix(gemspec) ⇒ Object
-
.core_path ⇒ Object
-
.deserialize_combined_gem(gemspec, hash) ⇒ Object
-
.deserialize_core ⇒ Object
-
.deserialize_rbs_collection_gem(gemspec, hash) ⇒ Object
-
.deserialize_stdlib_require(require) ⇒ Object
-
.deserialize_yard_gem(gemspec) ⇒ Object
-
.has_rbs_collection?(gemspec, hash) ⇒ Boolean
-
.has_yard?(gemspec) ⇒ Boolean
-
.rbs_collection_path(gemspec, hash) ⇒ Object
-
.rbs_collection_path_prefix(gemspec) ⇒ Object
-
.serialize_combined_gem(gemspec, hash, pins) ⇒ Object
-
.serialize_core(pins) ⇒ Object
-
.serialize_rbs_collection_gem(gemspec, hash, pins) ⇒ Object
-
.serialize_stdlib_require(require, pins) ⇒ Object
-
.serialize_yard_gem(gemspec, pins) ⇒ Object
-
.stdlib_path ⇒ Object
-
.stdlib_require_path(require) ⇒ Object
-
.uncache_core ⇒ Object
-
.uncache_gem(gemspec, out: nil) ⇒ Object
-
.uncache_stdlib ⇒ Object
-
.work_dir ⇒ String
The working directory for the current Ruby, RBS, and Solargraph versions.
-
.yard_gem_path(gemspec) ⇒ Object
-
.yardoc_path(gemspec) ⇒ Object
Methods included from Logging
logger
Class Method Details
.base_dir ⇒ String
The base directory where cached YARD documentation and serialized pins are serialized
12
13
14
15
16
17
18
|
# File 'lib/solargraph/pin_cache.rb', line 12
def base_dir
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.
129
130
131
|
# File 'lib/solargraph/pin_cache.rb', line 129
def clear
FileUtils.rm_rf base_dir, secure: true
end
|
.combined_path(gemspec, hash) ⇒ Object
93
94
95
|
# File 'lib/solargraph/pin_cache.rb', line 93
def combined_path(gemspec, hash)
File.join(work_dir, 'combined', "#{gemspec.name}-#{gemspec.version}-#{hash || 0}.ser")
end
|
.combined_path_prefix(gemspec) ⇒ Object
97
98
99
|
# File 'lib/solargraph/pin_cache.rb', line 97
def combined_path_prefix(gemspec)
File.join(work_dir, 'combined', "#{gemspec.name}-#{gemspec.version}-")
end
|
.core_path ⇒ Object
49
50
51
|
# File 'lib/solargraph/pin_cache.rb', line 49
def core_path
File.join(work_dir, 'core.ser')
end
|
.deserialize_combined_gem(gemspec, hash) ⇒ Object
105
106
107
|
# File 'lib/solargraph/pin_cache.rb', line 105
def deserialize_combined_gem gemspec, hash
load(combined_path(gemspec, hash))
end
|
.deserialize_core ⇒ Object
53
54
55
|
# File 'lib/solargraph/pin_cache.rb', line 53
def deserialize_core
load(core_path)
end
|
.deserialize_rbs_collection_gem(gemspec, hash) ⇒ Object
85
86
87
|
# File 'lib/solargraph/pin_cache.rb', line 85
def deserialize_rbs_collection_gem(gemspec, hash)
load(rbs_collection_path(gemspec, hash))
end
|
.deserialize_stdlib_require(require) ⇒ Object
41
42
43
|
# File 'lib/solargraph/pin_cache.rb', line 41
def deserialize_stdlib_require require
load(stdlib_require_path(require))
end
|
.deserialize_yard_gem(gemspec) ⇒ Object
65
66
67
|
# File 'lib/solargraph/pin_cache.rb', line 65
def deserialize_yard_gem(gemspec)
load(yard_gem_path(gemspec))
end
|
.has_rbs_collection?(gemspec, hash) ⇒ Boolean
109
110
111
|
# File 'lib/solargraph/pin_cache.rb', line 109
def has_rbs_collection?(gemspec, hash)
exist?(rbs_collection_path(gemspec, hash))
end
|
.has_yard?(gemspec) ⇒ Boolean
73
74
75
|
# File 'lib/solargraph/pin_cache.rb', line 73
def has_yard?(gemspec)
exist?(yard_gem_path(gemspec))
end
|
.rbs_collection_path(gemspec, hash) ⇒ Object
77
78
79
|
# File 'lib/solargraph/pin_cache.rb', line 77
def rbs_collection_path(gemspec, hash)
File.join(work_dir, 'rbs', "#{gemspec.name}-#{gemspec.version}-#{hash || 0}.ser")
end
|
.rbs_collection_path_prefix(gemspec) ⇒ Object
81
82
83
|
# File 'lib/solargraph/pin_cache.rb', line 81
def rbs_collection_path_prefix(gemspec)
File.join(work_dir, 'rbs', "#{gemspec.name}-#{gemspec.version}-")
end
|
.serialize_combined_gem(gemspec, hash, pins) ⇒ Object
101
102
103
|
# File 'lib/solargraph/pin_cache.rb', line 101
def serialize_combined_gem(gemspec, hash, pins)
save(combined_path(gemspec, hash), pins)
end
|
.serialize_core(pins) ⇒ Object
57
58
59
|
# File 'lib/solargraph/pin_cache.rb', line 57
def serialize_core pins
save(core_path, pins)
end
|
.serialize_rbs_collection_gem(gemspec, hash, pins) ⇒ Object
89
90
91
|
# File 'lib/solargraph/pin_cache.rb', line 89
def serialize_rbs_collection_gem(gemspec, hash, pins)
save(rbs_collection_path(gemspec, hash), pins)
end
|
.serialize_stdlib_require(require, pins) ⇒ Object
45
46
47
|
# File 'lib/solargraph/pin_cache.rb', line 45
def serialize_stdlib_require require, pins
save(stdlib_require_path(require), pins)
end
|
.serialize_yard_gem(gemspec, pins) ⇒ Object
69
70
71
|
# File 'lib/solargraph/pin_cache.rb', line 69
def serialize_yard_gem(gemspec, pins)
save(yard_gem_path(gemspec), pins)
end
|
.stdlib_path ⇒ Object
33
34
35
|
# File 'lib/solargraph/pin_cache.rb', line 33
def stdlib_path
File.join(work_dir, 'stdlib')
end
|
.stdlib_require_path(require) ⇒ Object
37
38
39
|
# File 'lib/solargraph/pin_cache.rb', line 37
def stdlib_require_path require
File.join(stdlib_path, "#{require}.ser")
end
|
.uncache_core ⇒ Object
113
114
115
|
# File 'lib/solargraph/pin_cache.rb', line 113
def uncache_core
uncache(core_path)
end
|
.uncache_gem(gemspec, out: nil) ⇒ Object
121
122
123
124
125
126
|
# File 'lib/solargraph/pin_cache.rb', line 121
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
|
.uncache_stdlib ⇒ Object
117
118
119
|
# File 'lib/solargraph/pin_cache.rb', line 117
def uncache_stdlib
uncache(stdlib_path)
end
|
.work_dir ⇒ String
The working directory for the current Ruby, RBS, and Solargraph versions.
23
24
25
26
27
|
# File 'lib/solargraph/pin_cache.rb', line 23
def work_dir
File.join(base_dir, "ruby-#{RUBY_VERSION}", "rbs-#{RBS::VERSION}", "solargraph-#{Solargraph::VERSION}")
end
|
.yard_gem_path(gemspec) ⇒ Object
61
62
63
|
# File 'lib/solargraph/pin_cache.rb', line 61
def yard_gem_path gemspec
File.join(work_dir, 'yard', "#{gemspec.name}-#{gemspec.version}.ser")
end
|
.yardoc_path(gemspec) ⇒ Object
29
30
31
|
# File 'lib/solargraph/pin_cache.rb', line 29
def yardoc_path gemspec
File.join(base_dir, "yard-#{YARD::VERSION}", "#{gemspec.name}-#{gemspec.version}.yardoc")
end
|