Module: Solargraph::Yardoc

Defined in:
lib/solargraph/yardoc.rb

Overview

Methods for caching and loading YARD documentation for gems.

Class Method Summary collapse

Class Method Details

.cache(gemspec) ⇒ String

Build and cache a gem’s yardoc and return the path. If the cache already exists, do nothing and return the path.

Parameters:

  • gemspec (Gem::Specification)

Returns:

  • (String)

    The path to the cached yardoc.



14
15
16
17
18
19
20
21
22
23
# File 'lib/solargraph/yardoc.rb', line 14

def cache(gemspec)
  path = PinCache.yardoc_path gemspec
  return path if cached?(gemspec)

  Solargraph.logger.info "Caching yardoc for #{gemspec.name} #{gemspec.version}"
  Dir.chdir gemspec.gem_dir do
    `yardoc --db #{path} --no-output --plugin solargraph`
  end
  path
end

.cached?(gemspec) ⇒ Boolean

True if the gem yardoc is cached.

Parameters:

  • gemspec (Gem::Specification)

Returns:

  • (Boolean)


28
29
30
31
# File 'lib/solargraph/yardoc.rb', line 28

def cached?(gemspec)
  yardoc = File.join(PinCache.yardoc_path(gemspec), 'complete')
  File.exist?(yardoc)
end

.load!(gemspec) ⇒ Array<YARD::CodeObjects::Base>

Note:

This method modifies the global YARD registry.

Load a gem’s yardoc and return its code objects.

Parameters:

  • gemspec (Gem::Specification)

Returns:

  • (Array<YARD::CodeObjects::Base>)


44
45
46
47
# File 'lib/solargraph/yardoc.rb', line 44

def load!(gemspec)
  YARD::Registry.load! PinCache.yardoc_path gemspec
  YARD::Registry.all
end

.processing?(gemspec) ⇒ Boolean

Returns:

  • (Boolean)


33
34
35
36
# File 'lib/solargraph/yardoc.rb', line 33

def processing?(gemspec)
  yardoc = File.join(PinCache.yardoc_path(gemspec), 'processing')
  File.exist?(yardoc)
end