class Longleaf::ApplicationConfigDeserializer
Deserializer for application configuration files
Public Class Methods
absolution(base_pathname, file_path)
click to toggle source
# File lib/longleaf/services/application_config_deserializer.rb, line 88 def self.absolution(base_pathname, file_path) if file_path.nil? nil else path = Pathname.new(file_path) if path.absolute? path = path.expand_path.to_s else path = (base_pathname + path).to_s end end end
deserialize(config_path, format: 'yaml')
click to toggle source
Deserializes a valid application configuration file as a ApplicationConfigManager
option @param config_path [String] file path to the service and storage mapping configuration file @param format [String] encoding format of the config file return [ApplicationConfigManager] manager for the loaded configuration
# File lib/longleaf/services/application_config_deserializer.rb, line 15 def self.deserialize(config_path, format: 'yaml') content = load_config_file(config_path) config = load(content, format) config_md5 = Digest::MD5.hexdigest(content) make_paths_absolute(config_path, config) ApplicationConfigValidator.new(config).validate_config.raise_if_invalid ApplicationConfigManager.new(config, config_md5) end
from_yaml(content)
click to toggle source
# File lib/longleaf/services/application_config_deserializer.rb, line 49 def self.from_yaml(content) begin YAML.safe_load(content, [], [], true) rescue => err raise Longleaf::ConfigurationError.new(err) end end
load(content, format)
click to toggle source
Deserialize a configuration file into a hash @param content [String] the contents of the application configuration file @param format [String] encoding format of the config file return [Hash] hash containing the configuration
# File lib/longleaf/services/application_config_deserializer.rb, line 40 def self.load(content, format) case format when 'yaml' from_yaml(content) else raise ArgumentError.new("Invalid deserialization format #{format} specified") end end
make_file_paths_absolute(base_pathname, properties)
click to toggle source
# File lib/longleaf/services/application_config_deserializer.rb, line 75 def self.make_file_paths_absolute(base_pathname, properties) path = properties[AF::LOCATION_PATH] return nil if path.nil? uri = URI(path) if uri.scheme.nil? || uri.scheme.casecmp("file") == 0 absolution(base_pathname, uri.path) else path end end
make_paths_absolute(config_path, config)
click to toggle source
# File lib/longleaf/services/application_config_deserializer.rb, line 57 def self.make_paths_absolute(config_path, config) base_pathname = Pathname.new(config_path).expand_path.parent config[AF::LOCATIONS].each do |name, properties| properties[AF::LOCATION_PATH] = make_file_paths_absolute(base_pathname, properties) # Resolve single field metadata location into expanded form md_config = properties[AF::METADATA_CONFIG] if md_config.nil? next end if md_config.is_a?(String) md_config = { AF::LOCATION => m_config } end md_config[AF::LOCATION_PATH] = make_file_paths_absolute(base_pathname, md_config) end end
Private Class Methods
load_config_file(config_path)
click to toggle source
# File lib/longleaf/services/application_config_deserializer.rb, line 27 def self.load_config_file(config_path) begin File.read(config_path) rescue Errno::ENOENT raise Longleaf::ConfigurationError.new( "Configuration file #{config_path} does not exist.") end end