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 = path_for(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(path_for(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>)


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

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

.path_for(gemspec) ⇒ String

Get the absolute path for a cached gem yardoc.

Parameters:

  • gemspec (Gem::Specification)

Returns:

  • (String)


37
38
39
# File 'lib/solargraph/yardoc.rb', line 37

def path_for(gemspec)
  File.join(Solargraph::Cache.base_dir, "yard-#{YARD::VERSION}", "#{gemspec.name}-#{gemspec.version}.yardoc")
end