Class: Longleaf::ServiceMappingManager
- Inherits:
-
Object
- Object
- Longleaf::ServiceMappingManager
- Defined in:
- lib/longleaf/services/service_mapping_manager.rb
Overview
Manager which loads and provides access to location to service mappings
Instance Method Summary collapse
-
#initialize(config) ⇒ ServiceMappingManager
constructor
A new instance of ServiceMappingManager.
-
#list_services(loc_name) ⇒ Array
Gets a list of service names associated with the given location.
Constructor Details
#initialize(config) ⇒ ServiceMappingManager
Returns a new instance of ServiceMappingManager.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/longleaf/services/service_mapping_manager.rb', line 10 def initialize(config) raise ArgumentError.new("Configuration must be provided") if config.nil? || config.empty? mappings_config = config[AF::SERVICE_MAPPINGS] raise ArgumentError.new("Service mappings configuration must be provided") if mappings_config.nil? @loc_to_services = Hash.new mappings_config.each do |mapping| locations = mapping[AF::LOCATIONS] services = mapping[AF::SERVICES] locations = [locations] if locations.is_a?(String) services = [services] if services.is_a?(String) locations.each do |loc_name| @loc_to_services[loc_name] = Array.new unless @loc_to_services.key?(loc_name) service_set = @loc_to_services[loc_name] if services.is_a?(String) service_set.push(services) else service_set.concat(services) end end end @loc_to_services.each { |loc, services| services.uniq! } @loc_to_services.freeze end |
Instance Method Details
#list_services(loc_name) ⇒ Array
Gets a list of service names associated with the given location
44 45 46 |
# File 'lib/longleaf/services/service_mapping_manager.rb', line 44 def list_services(loc_name) @loc_to_services[loc_name] || [] end |