Command
A tool to view documentation in the console like `ri`
The location in {YARD::CONFIG_DIR} where the YRI cache file is loaded from.
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")
@return [Array<String>] a list of extra search paths @since 0.6.0
A file containing all paths, delimited by newlines, to search for yardoc databases. @since 0.5.1
# File lib/yard/cli/yri.rb, line 30 def initialize super @cache = {} @search_paths = [] add_default_paths add_gem_paths load_cache @search_paths.uniq! end
Helper method to run the utility on an instance. @see run
# File lib/yard/cli/yri.rb, line 28 def self.run(*args) new.run(*args) end
# File lib/yard/cli/yri.rb, line 40 def description "A tool to view documentation in the console like `ri`" end
Runs the command-line utility.
@example
YRI.new.run('String#reverse')
@param [Array<String>] args each tokenized argument
# File lib/yard/cli/yri.rb, line 49 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 exit(1) elsif object = find_object(@name) print_object(object) else STDERR.puts "No documentation for `#{@name}'" exit(1) end end
Caches the .yardoc file where an object can be found in the {CACHE_FILE} @return [void]
# File lib/yard/cli/yri.rb, line 81 def cache_object(name, path) return if path == Registry.yardoc_file @cache[name] = path File.open!(CACHE_FILE, 'w') do |file| @cache.each do |key, value| file.puts("#{key} #{value}") end end end
Locates an object by name starting in the cached paths and then searching through any search paths.
@param [String] name the full name of the object @return [CodeObjects::Base] an object if found @return [nil] if no object is found
# File lib/yard/cli/yri.rb, line 109 def find_object(name) @search_paths.unshift(@cache[name]) if @cache[name] @search_paths.unshift(Registry.yardoc_file) # Try to load it from in memory cache log.debug "Searching for #{name} in memory" if obj = try_load_object(name, nil) return obj end log.debug "Searching for #{name} in search paths" @search_paths.each do |path| next unless File.exist?(path) log.debug "Searching for #{name} in #{path}..." Registry.load(path) if obj = try_load_object(name, path) return obj end end nil end
@param [CodeObjects::Base] object the object to print. @return [String] the formatted output for an object.
# File lib/yard/cli/yri.rb, line 94 def print_object(object) if object.type == :method && object.is_alias? tmp = P(object.namespace, (object.scope == :instance ? "#" : "") + object.namespace.aliases[object].to_s) object = tmp unless YARD::CodeObjects::Proxy === tmp end object.format(:serializer => @serializer) end
Generated with the Darkfish Rdoc Generator 2.