class AppConfigLoader::Parser
Public Class Methods
new(use_domain = false)
click to toggle source
# File lib/app_config_loader/parser.rb, line 5 def initialize(use_domain = false) @use_domain = use_domain end
Public Instance Methods
parse(content)
click to toggle source
Parse a YAML format text and returns flattened list of all key entries
@return Array<KeyEntry> list of key entries
# File lib/app_config_loader/parser.rb, line 12 def parse(content) flatten_keys YAML.load(content) end
Private Instance Methods
flatten_keys(cfg, current_full_key = nil)
click to toggle source
# File lib/app_config_loader/parser.rb, line 18 def flatten_keys(cfg, current_full_key = nil) cfg.reduce([]) do |flattened, (key, value)| raise InvalidConfigKey, 'config key component must be a string' unless key.is_a?(String) this_key = current_full_key ? "#{current_full_key}.#{key}" : key if value.is_a? Hash flattened += flatten_keys value, this_key else flattened << ConfigEntry.new(this_key, value, @use_domain) end flattened end end