Class: OptParseValidator::OptionsFiles
- Inherits:
-
Array
- Object
- Array
- OptParseValidator::OptionsFiles
- Defined in:
- lib/opt_parse_validator/options_files.rb
Overview
Options Files container
Instance Method Summary collapse
- #<<(file_path) ⇒ Self
- #parse(symbolize_keys = false) ⇒ Hash
-
#supported_extensions ⇒ Array<String>
The downcased supported extensions list.
Instance Method Details
#<<(file_path) ⇒ Self
21 22 23 24 25 26 27 28 29 |
# File 'lib/opt_parse_validator/options_files.rb', line 21 def <<(file_path) return self unless File.exist?(file_path) ext = File.extname(file_path).delete('.') raise Error, "The option file's extension '#{ext}' is not supported" unless supported_extensions.include?(ext) super(OptionsFile.const_get(ext.upcase).new(file_path)) end |
#parse(symbolize_keys = false) ⇒ Hash
34 35 36 37 38 39 40 |
# File 'lib/opt_parse_validator/options_files.rb', line 34 def parse(symbolize_keys = false) result = {} each { |option_file| result.deep_merge!(option_file.parse) } symbolize_keys ? result.deep_symbolize_keys : result end |
#supported_extensions ⇒ Array<String>
9 10 11 12 13 14 15 16 |
# File 'lib/opt_parse_validator/options_files.rb', line 9 def supported_extensions extensions = OptionsFile.constants.select do |const| name = OptionsFile.const_get(const) name.is_a?(Class) && name != OptionsFile::Base end extensions.map { |sym| sym.to_s.downcase } end |