module YARD::Registry

def all(*types)

Other tags:
    See: CodeObjects::Base#type -

Returns:
  • (Array) - the list of objects found

Parameters:
  • types (Array) -- an optional list of types to narrow the

Other tags:
    Example: Returns all classes and modules -
    Example: Returns all objects -
def all(*types)
  if types.empty?
    thread_local_store.values.select {|obj| obj != root }
  else
    list = []
    types.each do |type|
      list += thread_local_store.values_for_type(type)
    end
    list
  end
end

def at(path) path ? thread_local_store[path] : nil end

Returns:
  • (nil) - if no object is found
  • (CodeObjects::Base) - the object at path

Parameters:
  • path (String, :root) -- the pathname to look for. If +path+ is +root+,
def at(path) path ? thread_local_store[path] : nil end

def checksum_for(data)

Returns:
  • (String) - the SHA1 checksum for data

Parameters:
  • data (String) -- data to checksum
def checksum_for(data)
  Digest::SHA1.hexdigest(data)
end

def checksums

Returns:
  • (Hash{String => String}) - a set of checksums for files
def checksums
  thread_local_store.checksums
end

def clear

Returns:
  • (void) -
def clear
  self.thread_local_store = RegistryStore.new
end

def delete(object)

Returns:
  • (void) -

Parameters:
  • object (CodeObjects::Base) -- the object to remove
def delete(object)
  thread_local_store.delete(object.path)
end

def delete_from_disk

Returns:
  • (void) -
def delete_from_disk
  thread_local_store.destroy
end

def each(&block)

Iterates over {all} with no arguments
def each(&block)
  all.each(&block)
end

def global_yardoc_file(spec, for_writing = false)

def global_yardoc_file(spec, for_writing = false)
  path = spec.doc_dir
  yfile = spec.doc_dir(DEFAULT_YARDOC_FILE)
  if for_writing
    if File.writable?(path) ||
       (!File.directory?(path) && File.writable?(File.dirname(path)))
      return yfile
    end
  elsif !for_writing && File.exist?(yfile)
    return yfile
  end
end

def instance; self end

Returns:
  • (Registry) - returns the registry instance

Deprecated:
  • use Registry.methodname directly.
def instance; self end

def load(files = [], reparse = false)

Raises:
  • (ArgumentError) - if files is not a String or Array

Returns:
  • (Registry) - the registry object (for chaining)

Parameters:
  • reparse (Boolean) -- if reparse is false and a yardoc file already
  • files (String, Array) -- if +files+ is an Array, it should represent

Other tags:
    Example: Reparses files 'a' and 'b' regardless of whether yardoc file exists -
    Example: Loads the yardoc file or parses files 'a', 'b' and 'c' (but not both) -
def load(files = [], reparse = false)
  if files.is_a?(Array)
    if File.exist?(yardoc_file) && !reparse
      load_yardoc
    else
      size = thread_local_store.keys.size
      YARD.parse(files)
      save if thread_local_store.keys.size > size
    end
  elsif files.is_a?(String)
    load_yardoc(files)
  else
    raise ArgumentError, "Must take a list of files to parse or the .yardoc file to load."
  end
  self
end

def load!(file = yardoc_file)

Other tags:
    Since: - 0.5.1

Other tags:
    See: #load_all -
    See: #load_yardoc -

Returns:
  • (Registry) - the registry object (for chaining)

Parameters:
  • file (String) -- the yardoc file to load
def load!(file = yardoc_file)
  clear
  thread_local_store.load!(file)
  self
end

def load_all

Other tags:
    Since: - 0.5.1

Returns:
  • (Registry) - the registry object (for chaining)

Other tags:
    Example: Loads all objects from disk -
def load_all
  thread_local_store.load_all
  self
end

def load_yardoc(file = yardoc_file)

Returns:
  • (Registry) - the registry object (for chaining)

Parameters:
  • file (String) -- the yardoc file to load.
def load_yardoc(file = yardoc_file)
  clear
  thread_local_store.load(file)
  self
end

def local_yardoc_file(spec, for_writing = false)

def local_yardoc_file(spec, for_writing = false)
  path = Registry::LOCAL_YARDOC_INDEX
  FileUtils.mkdir_p(path) if for_writing
  path = File.join(path, "#{spec.full_name}.yardoc")
  if for_writing
    path
  else
    File.exist?(path) ? path : nil
  end
end

def locale(name)

Other tags:
    Since: - 0.8.3

Returns:
  • (I18n::Locale) - the locale object for +name+.

Parameters:
  • name (String) -- the locale name.
def locale(name)
  thread_local_store.locale(name)
end

def lock_for_writing(file = yardoc_file, &block)

Other tags:
    See: locked_for_writing? -
def lock_for_writing(file = yardoc_file, &block)
  thread_local_store.lock_for_writing(file, &block)
end

def locked_for_writing?(file = yardoc_file)

(see Serializers::YardocSerializer#locked_for_writing?)
def locked_for_writing?(file = yardoc_file)
  thread_local_store.locked_for_writing?(file)
end

def old_global_yardoc_file(spec, for_writing = false)

def old_global_yardoc_file(spec, for_writing = false)
  path = spec.full_gem_path
  yfile = File.join(path, DEFAULT_YARDOC_FILE)
  return yfile if for_writing && File.writable?(path)
  return yfile if !for_writing && File.exist?(yfile)
end

def partial_resolve(namespace, name, type = nil)

Parameters:
  • type (Symbol, nil) -- the {CodeObjects::Base#type} that the resolved
  • name (String) -- the name to look for
  • namespace (CodeObjects::NamespaceObject) -- the starting namespace
def partial_resolve(namespace, name, type = nil)
  obj = at(name) || at('#' + name) if namespace.root?
  return obj if obj && (type.nil? || obj.type == type)
  [CodeObjects::NSEP, CodeObjects::CSEP, ''].each do |s|
    next if s.empty? && name =~ /^\w/
    path = name
    path = [namespace.path, name].join(s) if namespace != root
    found = at(path)
    return found if found && (type.nil? || found.type == type)
  end
  nil
end

def paths(reload = false)

Returns:
  • (Array) - all of the paths in the registry.

Parameters:
  • reload (Boolean) -- whether to load entire database
def paths(reload = false)
  thread_local_store.keys(reload).map(&:to_s)
end

def po_dir

def po_dir
  Thread.current[:__yard_po_dir__] ||= DEFAULT_PO_DIR
end

def po_dir=(dir) Thread.current[:__yard_po_dir__] = dir end

def po_dir=(dir) Thread.current[:__yard_po_dir__] = dir end

def proxy_types

Deprecated:
  • The registry no longer globally tracks proxy types.

Other tags:
    Private: -

Returns:
  • ({String => Symbol}) - a set of unresolved paths and their assumed type
def proxy_types
  thread_local_store.proxy_types
end

def register(object)

Returns:
  • (CodeObjects::Base) - the registered object

Parameters:
  • object (CodeObjects::Base) -- the object to register
def register(object)
  return if object.is_a?(CodeObjects::Proxy)
  thread_local_store[object.path] = object
end

def resolve(namespace, name, inheritance = false, proxy_fallback = false, type = nil)

Other tags:
    See: P -

Returns:
  • (nil) - if +proxy_fallback+ is +false+ and no object was found.
  • (CodeObjects::Proxy) - a Proxy representing the object if
  • (CodeObjects::Base) - the object if it is found

Parameters:
  • type (Symbol, nil) -- the {CodeObjects::Base#type} that the resolved
  • proxy_fallback (Boolean) -- If +true+, returns a proxy representing
  • inheritance (Boolean) -- Follows inheritance chain (mixins, superclass)
  • name (String, Symbol) -- the name (or complex path) to look for from
  • namespace (CodeObjects::NamespaceObject, nil) -- the starting namespace

Other tags:
    Example: Looks for a complex path from a namespace -
    Example: Looks for a constant but returns a proxy if not found -
    Example: Looks for a class method respecting the inheritance tree -
    Example: Looks for a constant in the root namespace -
    Example: Looks for instance method #reverse starting from A::B::C -
def resolve(namespace, name, inheritance = false, proxy_fallback = false, type = nil)
  thread_local_resolver.lookup_by_path name,
    :namespace => namespace, :inheritance => inheritance,
    :proxy_fallback => proxy_fallback, :type => type
end

def root; thread_local_store[:root] end

Returns:
  • (CodeObjects::RootObject) - the root object in the namespace
def root; thread_local_store[:root] end

def save(merge = false, file = yardoc_file)

Returns:
  • (Boolean) - true if the file was saved

Parameters:
  • file (String) -- the yardoc file to save to
def save(merge = false, file = yardoc_file)
  thread_local_store.save(merge, file)
end

def single_object_db; Thread.current[:__yard_single_db__] end

def single_object_db; Thread.current[:__yard_single_db__] end

def single_object_db=(v) Thread.current[:__yard_single_db__] = v end

def single_object_db=(v) Thread.current[:__yard_single_db__] = v end

def thread_local_resolver

Other tags:
    Since: - 0.9.1
def thread_local_resolver
  Thread.current[:__yard_resolver__] ||= RegistryResolver.new
end

def thread_local_store

Other tags:
    Since: - 0.6.5
def thread_local_store
  Thread.current[:__yard_registry__] ||= clear
end

def thread_local_store=(value)

Other tags:
    Since: - 0.6.5
def thread_local_store=(value)
  Thread.current[:__yard_registry__] = value
end

def yardoc_file

def yardoc_file
  Thread.current[:__yard_yardoc_file__] ||= DEFAULT_YARDOC_FILE
end

def yardoc_file=(v) Thread.current[:__yard_yardoc_file__] = v end

def yardoc_file=(v) Thread.current[:__yard_yardoc_file__] = v end

def yardoc_file_for_gem(gem, ver_require = ">= 0", for_writing = false)

Returns:
  • (nil) - if +for_writing+ is set to false and no yardoc file
  • (String) - if +for_writing+ is set to +true+, returns the best

Parameters:
  • for_writing (Boolean) -- whether or not the method should search
  • ver_require (String) -- an optional Gem version requirement
  • gem (String) -- the name of the gem to search for
def yardoc_file_for_gem(gem, ver_require = ">= 0", for_writing = false)
  specs = YARD::GemIndex.find_all_by_name(gem, ver_require)
  return if specs.empty?
  result = nil
  specs.reverse.each do |spec|
    if gem =~ /^yard-doc-/
      path = File.join(spec.full_gem_path, DEFAULT_YARDOC_FILE)
      result = File.exist?(path) && !for_writing ? path : nil
      result ? break : next
    end
    if for_writing
      result = global_yardoc_file(spec, for_writing) ||
               old_global_yardoc_file(spec, for_writing) ||
               local_yardoc_file(spec, for_writing)
    else
      result = local_yardoc_file(spec, for_writing) ||
               global_yardoc_file(spec, for_writing) ||
               old_global_yardoc_file(spec, for_writing)
    end
    break if result
  end
  result
end