Module: OodAppkit::ConfigParser
- Defined in:
- lib/ood_appkit/config_parser.rb
Overview
Helper methods for parsing/deserializing yml configuration files
Defined Under Namespace
Classes: InvalidConfigPath
Constant Summary collapse
- YAML_VERSION =
Specific version hash in the yaml file to parse
'v1'- CLASS_ID =
Identifier used to distinguish class names when deserializing
'type'
Class Method Summary collapse
-
.parse(config:) ⇒ Hash
Parse/deserialize a configuration file or a set of configuration files.
Class Method Details
.parse(config:) ⇒ Hash
Parse/deserialize a configuration file or a set of configuration files
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/ood_appkit/config_parser.rb', line 20 def self.parse(config:) # use 'type' to distinguish class name in yaml file JSON.create_id = CLASS_ID config = Pathname.new(config.to_s). if config.file? parse_file config elsif config.directory? config.children.each_with_object({}) do |f, h| /^(.+)\.yml$/.match(f.basename.to_s) { h[$1.to_sym] = parse_file(f) } end else raise InvalidConfigPath, "invalid config path: #{config}" end end |