Class: YARD::CLI::YRI

Inherits:
Command show all
Defined in:
lib/yard/cli/yri.rb

Overview

A tool to view documentation in the console like ‘ri`

Constant Summary collapse

CACHE_FILE =

The location in YARD::CONFIG_DIR where the YRI cache file is loaded from.

File.expand_path(File.join(YARD::Config::CONFIG_DIR, 'yri_cache'))
SEARCH_PATHS_FILE =

A file containing all paths, delimited by newlines, to search for yardoc databases.

Since:

  • 0.5.1

File.expand_path(File.join(YARD::Config::CONFIG_DIR, 'yri_search_paths'))
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")

Returns:

Since:

  • 0.6.0

[]

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeYRI

Returns a new instance of YRI.



31
32
33
34
35
36
37
38
39
# 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) ⇒ Object

Helper method to run the utility on an instance.

See Also:



29
# File 'lib/yard/cli/yri.rb', line 29

def self.run(*args) new.run(*args) end

Instance Method Details

#descriptionObject



41
42
43
# File 'lib/yard/cli/yri.rb', line 41

def description
  "A tool to view documentation in the console like `ri`"
end

#run(*args) ⇒ Object

Runs the command-line utility.

Examples:

YRI.new.run('String#reverse')

Parameters:



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# 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