module YARD::CodeObjects::NamespaceMapper

def clear_separators

Returns:
  • (void) -
def clear_separators
  NamespaceMapper.invalidate
  NamespaceMapper.map = {}
  NamespaceMapper.rev_map = {}
end

def default_separator(value = nil)

Parameters:
  • value (String, nil) -- the default separator, or nil to return the
def default_separator(value = nil)
  if value
    NamespaceMapper.invalidate
    NamespaceMapper.default_separator = Regexp.quote value
  else
    NamespaceMapper.default_separator
  end
end

def invalidate

Returns:
  • (void) -
def invalidate
  @map_match = nil
  (@invalidation_callbacks || []).each(&:call)
end

def map

Returns:
  • (Hash) - a mapping of types to separators
def map
  @map ||= {}
end

def map_match

Returns:
  • (Regexp) - the full list of separators as a regexp match
def map_match
  @map_match ||= map.keys.map {|k| Regexp.quote k }.join('|')
end

def on_invalidate(&block)

the cache is cleared by invalidation.
Adds a callback that triggers when a new separator is registered or
def on_invalidate(&block)
  (@invalidation_callbacks ||= []).push(block)
end

def register_separator(sep, *valid_types)

Other tags:
    See: .on_invalidate -

Other tags:
    Example: Registering separators for a method object -

Parameters:
  • valid_types (Array) -- a list of object types that
  • sep (String) -- the separator string for the namespace
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

def rev_map

Returns:
  • (Hash) - a reverse mapping of separators to types
def rev_map
  @rev_map ||= {}
end

def separators

Returns:
  • (Array) - all of the registered separators
def separators
  NamespaceMapper.map.keys
end

def separators_for_type(type)

Returns:
  • (Array) - a list of separators registered to a type

Parameters:
  • type (String) -- the type to return separators for
def separators_for_type(type)
  NamespaceMapper.rev_map[type] || []
end

def separators_match

Returns:
  • (Regexp) - the regexp match of all separators
def separators_match
  NamespaceMapper.map_match
end

def types_for_separator(sep)

Returns:
  • (Array) - a list of types registered to a separator

Parameters:
  • sep (String) -- the separator to return types for
def types_for_separator(sep)
  NamespaceMapper.map[sep] || []
end

def unregister_separator_by_type(type)

Other tags:
    See: #register_separator -

Parameters:
  • type (Symbol) -- the type to unregister
def unregister_separator_by_type(type)
  seps = NamespaceMapper.rev_map[type]
  return unless seps
  
  seps.each {|s| NamespaceMapper.map.delete(s) }
  NamespaceMapper.rev_map.delete(type)
  NamespaceMapper.invalidate
end