Class: Copland::Implementation::SymbolSourceManager
- Inherits:
-
Object
- Object
- Copland::Implementation::SymbolSourceManager
- Defined in:
- lib/copland/impl/symbol-source-manager.rb
Overview
The implementation of the SymbolSourceManager service. It forms the central repository of all symbols in Copland, and which clients may query the values of any defined symbols.
Constant Summary collapse
- NOT_FOUND =
A unique value, used for identifying whether or not a value was found in a symbol source.
Object.new
Instance Method Summary collapse
-
#[](name) ⇒ Object
A convenience method that just delegates to #lookup.
-
#has_symbol?(name) ⇒ Boolean
Returns
true
if the source contains a symbol with the given name. -
#initialize(sources) ⇒ SymbolSourceManager
constructor
Create a new SymbolSourceManager, using the given array of source definitions.
-
#lookup(name, default = nil) ⇒ Object
Returns the value of the given symbol, or the value of
default
if no such symbol exists in source.
Constructor Details
#initialize(sources) ⇒ SymbolSourceManager
Create a new SymbolSourceManager, using the given array of source definitions.
99 100 101 102 |
# File 'lib/copland/impl/symbol-source-manager.rb', line 99 def initialize( sources ) @sources = sources.map { |entry| SymbolSourceDefinition.new( entry ) } @sources = Copland::Orderer.order( @sources ).map { |v| v.source } end |
Instance Method Details
#[](name) ⇒ Object
A convenience method that just delegates to #lookup.
124 125 126 |
# File 'lib/copland/impl/symbol-source-manager.rb', line 124 def []( name ) lookup( name ) end |
#has_symbol?(name) ⇒ Boolean
Returns true
if the source contains a symbol with the given name.
105 106 107 108 |
# File 'lib/copland/impl/symbol-source-manager.rb', line 105 def has_symbol?( name ) found = @sources.find { |source| source.has_symbol?( name ) } return !found.nil? end |
#lookup(name, default = nil) ⇒ Object
Returns the value of the given symbol, or the value of default
if no such symbol exists in source.
112 113 114 115 116 117 118 119 120 121 |
# File 'lib/copland/impl/symbol-source-manager.rb', line 112 def lookup( name, default=nil ) @sources.each do |source| value = source.lookup( name, NOT_FOUND ) if value != NOT_FOUND return value end end return default end |