Module: YARD::CodeObjects::NamespaceMapper
Relationships & Source Files | |
Extension / Inclusion / Inheritance Descendants | |
Extended In:
| |
Included In:
| |
Defined in: | lib/yard/code_objects/namespace_mapper.rb |
Overview
This module controls registration and accessing of namespace separators
for ::YARD::Registry
lookup.
Registering a Separator for a Namespace
-
#clear_separators ⇒ void
Clears the map of separators.
-
#default_separator(value = nil)
Gets or sets the default separator value to use when no separator for the namespace can be determined.
-
#register_separator(sep, *valid_types)
Registers a separator with an optional set of valid types that must follow the separator lexically.
-
#unregister_separator_by_type(type)
Unregisters a separator by a type.
Separator and Type Lookup Helpers
Invalidation callbacks
- .default_separator ⇒ String rw private
-
.invalidate ⇒ void
private
Invalidates all separators.
- .map ⇒ Hash private
- .map_match ⇒ Regexp private
-
.on_invalidate(&block)
Adds a callback that triggers when a new separator is registered or the cache is cleared by invalidation.
- .rev_map ⇒ Hash private
Class Attribute Details
.default_separator ⇒ String (rw, private)
# File 'lib/yard/code_objects/namespace_mapper.rb', line 137
attr_accessor :default_separator
Class Method Details
.invalidate ⇒ void
(private)
This method returns an undefined value.
Invalidates all separators
# File 'lib/yard/code_objects/namespace_mapper.rb', line 125
def invalidate @map_match = nil (@invalidation_callbacks || []).each(&:call) end
.map ⇒ Hash (private)
# File 'lib/yard/code_objects/namespace_mapper.rb', line 114
def map @map ||= {} end
.map_match ⇒ Regexp
(private)
.on_invalidate(&block)
Adds a callback that triggers when a new separator is registered or the cache is cleared by invalidation.
# File 'lib/yard/code_objects/namespace_mapper.rb', line 107
def on_invalidate(&block) (@invalidation_callbacks ||= []).push(block) end
.rev_map ⇒ Hash (private)
# File 'lib/yard/code_objects/namespace_mapper.rb', line 119
def rev_map @rev_map ||= {} end
Instance Method Details
#clear_separators ⇒ void
This method returns an undefined value.
Clears the map of separators.
# File 'lib/yard/code_objects/namespace_mapper.rb', line 55
def clear_separators NamespaceMapper.invalidate NamespaceMapper.map = {} NamespaceMapper.rev_map = {} end
#default_separator(value = nil)
Gets or sets the default separator value to use when no separator for the namespace can be determined.
# File 'lib/yard/code_objects/namespace_mapper.rb', line 68
def default_separator(value = nil) if value NamespaceMapper.invalidate NamespaceMapper.default_separator = Regexp.quote value else NamespaceMapper.default_separator end end
#register_separator(sep, *valid_types)
Registers a separator with an optional set of valid types that must follow the separator lexically.
Calls all callbacks defined by .on_invalidate after the separator is registered.
# File 'lib/yard/code_objects/namespace_mapper.rb', line 27
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 ⇒ Array<String>
# File 'lib/yard/code_objects/namespace_mapper.rb', line 80
def separators NamespaceMapper.map.keys end
#separators_for_type(type) ⇒ Array<Symbol
>
# File 'lib/yard/code_objects/namespace_mapper.rb', line 97
def separators_for_type(type) NamespaceMapper.rev_map[type] || [] end
#separators_match ⇒ Regexp
# File 'lib/yard/code_objects/namespace_mapper.rb', line 85
def separators_match NamespaceMapper.map_match end
#types_for_separator(sep) ⇒ Array<Symbol
>
# File 'lib/yard/code_objects/namespace_mapper.rb', line 91
def types_for_separator(sep) NamespaceMapper.map[sep] || [] end
#unregister_separator_by_type(type)
Unregisters a separator by a type.
# File 'lib/yard/code_objects/namespace_mapper.rb', line 43
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