module YARD::CodeObjects::NamespaceMapper

This module controls registration and accessing of namespace separators for {Registry} lookup.

@since 0.9.1

Attributes

default_separator[RW]

@return [String] the default separator when no separator can begin

determined.

Public Class Methods

invalidate() click to toggle source

Invalidates all separators @return [void]

# File lib/yard/code_objects/namespace_mapper.rb, line 99
def invalidate
  @map_match = nil
end
map() click to toggle source

@return [Hash] a mapping of types to separators

# File lib/yard/code_objects/namespace_mapper.rb, line 88
def map
  @map ||= {}
end
map_match() click to toggle source

@return [Regexp] the full list of separators as a regexp match

# File lib/yard/code_objects/namespace_mapper.rb, line 104
def map_match
  @map_match ||= @map.keys.map {|k| Regexp.quote k }.join('|')
end
rev_map() click to toggle source

@return [Hash] a reverse mapping of separators to types

# File lib/yard/code_objects/namespace_mapper.rb, line 93
def rev_map
  @rev_map ||= {}
end

Public Instance Methods

clear_separators() click to toggle source

Clears the map of separators.

@return [void]

# File lib/yard/code_objects/namespace_mapper.rb, line 38
def clear_separators
  NamespaceMapper.invalidate
  NamespaceMapper.map = {}
  NamespaceMapper.rev_map = {}
end
default_separator(value = nil) click to toggle source

Gets or sets the default separator value to use when no separator for the namespace can be determined.

@param value [String, nil] the default separator, or nil to return the

value

@example

default_separator "::"
# File lib/yard/code_objects/namespace_mapper.rb, line 51
def default_separator(value = nil)
  if value
    NamespaceMapper.default_separator = Regexp.quote value
  else
    NamespaceMapper.default_separator
  end
end
register_separator(sep, *valid_types) click to toggle source

Registers a separator with an optional set of valid types that must follow the separator lexically.

@param sep [String] the separator string for the namespace @param valid_types [Array<Symbol>] a list of object types that

must follow the separator. If the list is empty, any type can
follow the separator.

@example Registering separators for a method object

# Anything after a "#" denotes a method object
register_separator "#", :method
# Anything after a "." denotes a method object
register_separator ".", :method
# File lib/yard/code_objects/namespace_mapper.rb, line 23
def register_separator(sep, *valid_types)
  NamespaceMapper.invalidate

  valid_types.each do |t|
    NamespaceMapper.rev_map[t] ||= []
    NamespaceMapper.rev_map[t] << sep
  end

  NamespaceMapper.map[sep] ||= []
  NamespaceMapper.map[sep] += valid_types
end
separators() click to toggle source

@return [Array<String>] all of the registered separators

# File lib/yard/code_objects/namespace_mapper.rb, line 62
def separators
  NamespaceMapper.map.keys
end
separators_for_type(type) click to toggle source

@param type [String] the type to return separators for @return [Array<Symbol>] a list of separators registered to a type

# File lib/yard/code_objects/namespace_mapper.rb, line 79
def separators_for_type(type)
  NamespaceMapper.rev_map[type]
end
separators_match() click to toggle source

@return [Regexp] the regexp match of all separators

# File lib/yard/code_objects/namespace_mapper.rb, line 67
def separators_match
  NamespaceMapper.map_match
end
types_for_separator(sep) click to toggle source

@param sep [String] the separator to return types for @return [Array<Symbol>] a list of types registered to a separator

# File lib/yard/code_objects/namespace_mapper.rb, line 73
def types_for_separator(sep)
  NamespaceMapper.map[sep]
end