Module: XfOOrth::SymbolMap

Defined in:
lib/fOOrth/symbol_map.rb,
lib/fOOrth/library/introspection/symbol_map.rb

Overview

  • library/introspection/symbol_map.rb - Mapping support for introspection.

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.forward_mapObject (readonly)

Access to the mapping of names to symbols.



11
12
13
# File 'lib/fOOrth/symbol_map.rb', line 11

def forward_map
  @forward_map
end

.reverse_mapObject (readonly)

Access to the mapping of symbols to names.



14
15
16
# File 'lib/fOOrth/symbol_map.rb', line 14

def reverse_map
  @reverse_map
end

Class Method Details

.add_entry(name, presym = nil) ⇒ Object

Add a global mapping for a string to a symbol that will not collide with existing symbols.
Parameters:

  • name - The string to be mapped.

  • presym - A pre-assigned symbol value or nil to generate a symbol.


Returns:

  • The symbol that corresponds to the name.


Endemic Code Smells

  • :reek:ControlParameter – false positive



31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/fOOrth/symbol_map.rb', line 31

def self.add_entry(name, presym=nil)
  @sync.synchronize do
    unless (symbol = @forward_map[name])
      symbol = presym || (@incrementer.succ!).to_sym
      connect(name, symbol)
    else
      error "F90: Attempt to redefine #{name}." if presym && presym != symbol
    end

    symbol
  end
end

.map(name) ⇒ Object

Get the entry for the mapping string. Return nil if there is no entry.
Parameters:

  • name - The string to be looked up.


Returns:

  • A symbol or nil if the symbol is not in the map.



49
50
51
# File 'lib/fOOrth/symbol_map.rb', line 49

def self.map(name)
  @forward_map[name]
end

.map_info(name) ⇒ Object

Get mapping info for a method name.



10
11
12
13
14
# File 'lib/fOOrth/library/introspection/symbol_map.rb', line 10

def self.map_info(name)
  symbol = map(name)
  target = symbol ? symbol.to_s : "not found."
  [symbol,  [["Name", name], ["Mapping", target]]]
end

.restart(start) ⇒ Object

Reset the incrementer to the given string. This used for testing only.
Parameters:

  • start - The new starting point of the generated symbols.


Note:

  • FOR TESTING ONLY.



67
68
69
# File 'lib/fOOrth/symbol_map.rb', line 67

def self.restart(start)
  @incrementer = start
end

.unmap(mapped) ⇒ Object

Get the entry for the mapping symbol. Return nil if there is no entry.
Parameters:

  • mapped - The mapping of the desired symbol.


Returns:

  • The name or nil if the symbol is not in the map.



58
59
60
# File 'lib/fOOrth/symbol_map.rb', line 58

def self.unmap(mapped)
  @reverse_map[mapped]
end