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

Methods included from Logging

log_level, logger

Class Method Details

.base_dirString

The base directory where cached YARD documentation and serialized pins are serialized

Returns:

  • (String)


14
15
16
17
18
19
20
# File 'lib/solargraph/pin_cache.rb', line 14

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

.clearvoid

This method returns an undefined value.



189
190
191
# File 'lib/solargraph/pin_cache.rb', line 189

def clear
  FileUtils.rm_rf base_dir, secure: true
end

.combined_path(gemspec, hash) ⇒ String

Parameters:

  • gemspec (Gem::Specification)
  • hash (String, nil)

Returns:

  • (String)


136
137
138
# File 'lib/solargraph/pin_cache.rb', line 136

def combined_path gemspec, hash
  File.join(work_dir, 'combined', "#{gemspec.name}-#{gemspec.version}-#{hash || 0}.ser")
end

.combined_path_prefix(gemspec) ⇒ String

Parameters:

  • gemspec (Gem::Specification)

Returns:

  • (String)


142
143
144
# File 'lib/solargraph/pin_cache.rb', line 142

def combined_path_prefix gemspec
  File.join(work_dir, 'combined', "#{gemspec.name}-#{gemspec.version}-")
end

.core_pathString

Returns:

  • (String)


65
66
67
# File 'lib/solargraph/pin_cache.rb', line 65

def core_path
  File.join(work_dir, 'core.ser')
end

.deserialize_combined_gem(gemspec, hash) ⇒ Array<Pin::Base>?

Parameters:

  • gemspec (Gem::Specification)
  • hash (String, nil)

Returns:



157
158
159
# File 'lib/solargraph/pin_cache.rb', line 157

def deserialize_combined_gem gemspec, hash
  load(combined_path(gemspec, hash))
end

.deserialize_coreArray<Pin::Base>?

Returns:



70
71
72
# File 'lib/solargraph/pin_cache.rb', line 70

def deserialize_core
  load(core_path)
end

.deserialize_rbs_collection_gem(gemspec, hash) ⇒ Array<Pin::Base>?

Parameters:

  • gemspec (Gem::Specification)
  • hash (String, nil)

Returns:



121
122
123
# File 'lib/solargraph/pin_cache.rb', line 121

def deserialize_rbs_collection_gem gemspec, hash
  load(rbs_collection_path(gemspec, hash))
end

.deserialize_stdlib_require(require) ⇒ Array<Pin::Base>?

Parameters:

  • require (String)

Returns:



53
54
55
# File 'lib/solargraph/pin_cache.rb', line 53

def deserialize_stdlib_require require
  load(stdlib_require_path(require))
end

.deserialize_yard_gem(gemspec) ⇒ Array<Pin::Base>?

Parameters:

  • gemspec (Gem::Specification)

Returns:



88
89
90
# File 'lib/solargraph/pin_cache.rb', line 88

def deserialize_yard_gem gemspec
  load(yard_gem_path(gemspec))
end

.has_rbs_collection?(gemspec, hash) ⇒ Boolean

Parameters:

  • gemspec (Gem::Specification)
  • hash (String, nil)

Returns:

  • (Boolean)


164
165
166
# File 'lib/solargraph/pin_cache.rb', line 164

def has_rbs_collection? gemspec, hash
  exist?(rbs_collection_path(gemspec, hash))
end

.has_yard?(gemspec) ⇒ Boolean

Parameters:

  • gemspec (Gem::Specification)

Returns:

  • (Boolean)


101
102
103
# File 'lib/solargraph/pin_cache.rb', line 101

def has_yard? gemspec
  exist?(yard_gem_path(gemspec))
end

.rbs_collection_path(gemspec, hash) ⇒ String

Parameters:

  • gemspec (Gem::Specification)
  • hash (String, nil)

Returns:

  • (String)


108
109
110
# File 'lib/solargraph/pin_cache.rb', line 108

def rbs_collection_path gemspec, hash
  File.join(work_dir, 'rbs', "#{gemspec.name}-#{gemspec.version}-#{hash || 0}.ser")
end

.rbs_collection_path_prefix(gemspec) ⇒ String

Parameters:

  • gemspec (Gem::Specification)

Returns:

  • (String)


114
115
116
# File 'lib/solargraph/pin_cache.rb', line 114

def rbs_collection_path_prefix gemspec
  File.join(work_dir, 'rbs', "#{gemspec.name}-#{gemspec.version}-")
end

.serialize_combined_gem(gemspec, hash, pins) ⇒ void

This method returns an undefined value.

Parameters:

  • gemspec (Gem::Specification)
  • hash (String, nil)
  • pins (Array<Pin::Base>)


150
151
152
# File 'lib/solargraph/pin_cache.rb', line 150

def serialize_combined_gem gemspec, hash, pins
  save(combined_path(gemspec, hash), pins)
end

.serialize_core(pins) ⇒ void

This method returns an undefined value.

Parameters:



76
77
78
# File 'lib/solargraph/pin_cache.rb', line 76

def serialize_core pins
  save(core_path, pins)
end

.serialize_rbs_collection_gem(gemspec, hash, pins) ⇒ void

This method returns an undefined value.

Parameters:

  • gemspec (Gem::Specification)
  • hash (String, nil)
  • pins (Array<Pin::Base>)

    n



129
130
131
# File 'lib/solargraph/pin_cache.rb', line 129

def serialize_rbs_collection_gem gemspec, hash, pins
  save(rbs_collection_path(gemspec, hash), pins)
end

.serialize_stdlib_require(require, pins) ⇒ void

This method returns an undefined value.

Parameters:



60
61
62
# File 'lib/solargraph/pin_cache.rb', line 60

def serialize_stdlib_require require, pins
  save(stdlib_require_path(require), pins)
end

.serialize_yard_gem(gemspec, pins) ⇒ void

This method returns an undefined value.

Parameters:

  • gemspec (Gem::Specification)
  • pins (Array<Pin::Base>)


95
96
97
# File 'lib/solargraph/pin_cache.rb', line 95

def serialize_yard_gem gemspec, pins
  save(yard_gem_path(gemspec), pins)
end

.stdlib_pathString

Returns:

  • (String)


41
42
43
# File 'lib/solargraph/pin_cache.rb', line 41

def stdlib_path
  File.join(work_dir, 'stdlib')
end

.stdlib_require_path(require) ⇒ String

Parameters:

  • require (String)

Returns:

  • (String)


47
48
49
# File 'lib/solargraph/pin_cache.rb', line 47

def stdlib_require_path require
  File.join(stdlib_path, "#{require}.ser")
end

.uncache_corevoid

This method returns an undefined value.



169
170
171
# File 'lib/solargraph/pin_cache.rb', line 169

def uncache_core
  uncache(core_path)
end

.uncache_gem(gemspec, out: nil) ⇒ void

This method returns an undefined value.

Parameters:

  • gemspec (Gem::Specification)
  • out (IO, StringIO, nil) (defaults to: nil)


181
182
183
184
185
186
# File 'lib/solargraph/pin_cache.rb', line 181

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_stdlibvoid

This method returns an undefined value.



174
175
176
# File 'lib/solargraph/pin_cache.rb', line 174

def uncache_stdlib
  uncache(stdlib_path)
end

.work_dirString

The working directory for the current Ruby, RBS, and Solargraph versions.

Returns:

  • (String)


25
26
27
28
29
# File 'lib/solargraph/pin_cache.rb', line 25

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

.yard_gem_path(gemspec) ⇒ String

Parameters:

  • gemspec (Gem::Specification)

Returns:

  • (String)


82
83
84
# File 'lib/solargraph/pin_cache.rb', line 82

def yard_gem_path gemspec
  File.join(work_dir, 'yard', "#{gemspec.name}-#{gemspec.version}.ser")
end

.yardoc_path(gemspec) ⇒ String

Parameters:

  • gemspec (Gem::Specification)

Returns:

  • (String)


33
34
35
36
37
38
# File 'lib/solargraph/pin_cache.rb', line 33

def yardoc_path gemspec
  File.join(base_dir,
            "yard-#{YARD::VERSION}",
            "yard-activesupport-concern-#{YARD::ActiveSupport::Concern::VERSION}",
            "#{gemspec.name}-#{gemspec.version}.yardoc")
end