123456789_123456789_123456789_123456789_123456789_

Class: YARD::CLI::Gems

Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
self, Command
Instance Chain:
self, Command
Inherits: YARD::CLI::Command
Defined in: lib/yard/cli/gems.rb

Overview

Since:

  • 0.6.0

Class Method Summary

Command - Inherited

.run

Helper method to run the utility on an instance.

Instance Method Summary

Command - Inherited

Constructor Details

.newGems

Since:

  • 0.6.0

[ GitHub ]

  
# File 'lib/yard/cli/gems.rb', line 6

def initialize
  @rebuild = false
  @gems = []
end

Instance Method Details

#add_gems(gems) (private)

Since:

  • 0.6.0

[ GitHub ]

  
# File 'lib/yard/cli/gems.rb', line 47

def add_gems(gems)
  0.step(gems.size - 1, 2) do |index|
    gem = gems[index]
    ver_require = gems[index + 1] || ">= 0"
    specs = YARD::GemIndex.find_all_by_name(gem, ver_require)
    if specs.empty?
      log.warn "#{gem} #{ver_require} could not be found in RubyGems index"
    else
      @gems += specs
    end
  end
end

#build_gems (private)

Builds .yardoc files for all non-existing gems

Since:

  • 0.6.0

[ GitHub ]

  
# File 'lib/yard/cli/gems.rb', line 27

def build_gems
  require 'rubygems'
  @gems.each do |spec|
    ver = "= #{spec.version}"
    dir = Registry.yardoc_file_for_gem(spec.name, ver)
    if dir && File.directory?(dir) && !@rebuild
      log.debug "#{spec.name} index already exists at '#{dir}'"
    else
      yfile = Registry.yardoc_file_for_gem(spec.name, ver, true)
      next unless yfile
      next unless File.directory?(spec.full_gem_path)
      Registry.clear
      Dir.chdir(spec.full_gem_path) do
        log.info "Building yardoc index for gem: #{spec.full_name}"
        Yardoc.run('--no-stats', '-n', '-b', yfile)
      end
    end
  end
end

#description

Since:

  • 0.6.0

[ GitHub ]

  
# File 'lib/yard/cli/gems.rb', line 11

def description; "Builds YARD index for gems" end

#optparse(*args) (private)

Parses options

Since:

  • 0.6.0

[ GitHub ]

  
# File 'lib/yard/cli/gems.rb', line 61

def optparse(*args)
  opts = OptionParser.new
  opts.banner = 'Usage: yard gems [options] [gem_name [version]]'
  opts.separator ""
  opts.separator "#{description}. If no gem_name is given,"
  opts.separator "all gems are built."
  opts.separator ""
  opts.on('--rebuild', 'Rebuilds index') do
    @rebuild = true
  end

  common_options(opts)
  parse_options(opts, args)
  add_gems(args)

  if !args.empty? && @gems.empty?
    log.error "No specified gems could be found for command"
  elsif @gems.empty?
    @gems += YARD::GemIndex.all if @gems.empty?
  end
end

#run(*args) ⇒ void

This method returns an undefined value.

Runs the commandline utility, parsing arguments and generating ::YARD indexes for gems.

Parameters:

Since:

  • 0.6.0

[ GitHub ]

  
# File 'lib/yard/cli/gems.rb', line 18

def run(*args)
  require 'rubygems'
  optparse(*args)
  build_gems
end