Class: YARD::CLI::YRI
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/yri.rb |
Overview
A tool to view documentation in the console like ri
Constant Summary
-
CACHE_FILE =
The location in YARD::CONFIG_DIR where the
YRI
cache file is loaded from.File. (File.join(YARD::Config::CONFIG_DIR, 'yri_cache'))
-
DEFAULT_SEARCH_PATHS =
Default search paths that should be loaded dynamically into
YRI
. These paths take precedence over all other paths (SEARCH_PATHS_FILE and RubyGems paths). To add a path, call:DEFAULT_SEARCH_PATHS.push("/path/to/.yardoc")
[]
-
SEARCH_PATHS_FILE =
A file containing all paths, delimited by newlines, to search for yardoc databases.
File. (File.join(YARD::Config::CONFIG_DIR, 'yri_search_paths'))
Class Method Summary
- .new ⇒ YRI constructor
-
.run(*args)
Helper method to run the utility on an instance.
Command
- Inherited
.run | Helper method to run the utility on an instance. |
Instance Method Summary
- #description
-
#run(*args)
Runs the command-line utility.
-
#add_default_paths
private
Adds paths in SEARCH_PATHS_FILE
-
#add_gem_paths ⇒ void
private
Adds all RubyGems yardoc files to search paths.
-
#load_cache ⇒ void
private
Loads CACHE_FILE
-
#optparse(*args)
private
Parses commandline options.
-
#try_load_object(name, cache_path) ⇒ void
private
Tries to load the object with name.
Command
- Inherited
Constructor Details
.new ⇒ YRI
# File 'lib/yard/cli/yri.rb', line 31
def initialize super @cache = {} @search_paths = [] add_default_paths add_gem_paths load_cache @search_paths.uniq! end
Class Method Details
.run(*args)
Helper method to run the utility on an instance.
# File 'lib/yard/cli/yri.rb', line 29
def self.run(*args) new.run(*args) end
Instance Method Details
#add_default_paths (private)
Adds paths in SEARCH_PATHS_FILE
# File 'lib/yard/cli/yri.rb', line 181
def add_default_paths @search_paths.concat(DEFAULT_SEARCH_PATHS) return unless File.file?(SEARCH_PATHS_FILE) paths = File.readlines(SEARCH_PATHS_FILE).map(&:strip) @search_paths.concat(paths) end
#add_gem_paths ⇒ void
(private)
This method returns an undefined value.
Adds all RubyGems yardoc files to search paths
# File 'lib/yard/cli/yri.rb', line 161
def add_gem_paths require 'rubygems' gem_paths = [] YARD::GemIndex.each do |spec| yfile = Registry.yardoc_file_for_gem(spec.name) next if yfile.nil? if spec.name =~ /^yard-doc-/ gem_paths.unshift(yfile) else gem_paths.push(yfile) end end @search_paths += gem_paths rescue LoadError nil # noop end
#description
[ GitHub ]# File 'lib/yard/cli/yri.rb', line 41
def description "A tool to view documentation in the console like `ri`" end
#load_cache ⇒ void
(private)
This method returns an undefined value.
Loads CACHE_FILE
# File 'lib/yard/cli/yri.rb', line 151
def load_cache return unless File.file?(CACHE_FILE) File.readlines(CACHE_FILE).each do |line| line = line.strip.split(/\s+/) @cache[line[0]] = line[1] end end
#optparse(*args) (private)
Parses commandline options.
# File 'lib/yard/cli/yri.rb', line 190
def optparse(*args) opts = OptionParser.new opts. = "Usage: yri [options] <Path to object>" opts.separator "Example: yri String#gsub" opts.separator "" opts.separator "General Options:" opts.on('-b', '--db FILE', 'Use a specified .yardoc db to search in') do |yfile| @search_paths.unshift(yfile) end opts.on('-T', '--no-pager', 'No pager') do @serializer = YARD::Serializers::StdoutSerializer.new end opts.on('-p PAGER', '--pager') do |pager| @serializer = YARD::Serializers::ProcessSerializer.new(pager) end (opts) (opts, args) @name = args.first end
#run(*args)
Runs the command-line utility.
# File 'lib/yard/cli/yri.rb', line 50
def run(*args) optparse(*args) if ::RbConfig::CONFIG['host_os'] =~ /mingw|win32/ @serializer ||= YARD::Serializers::StdoutSerializer.new else @serializer ||= YARD::Serializers::ProcessSerializer.new('less') end if @name.nil? || @name.strip.empty? print_usage return exit(1) end object = find_object(@name) if object print_object(object) else STDERR.puts "No documentation for `#{@name}'" return exit(1) end end
#try_load_object(name, cache_path) ⇒ void
(private)
This method returns an undefined value.
Tries to load the object with name. If successful, caches the object with the cache_path