Class: Dpl::ConfigFile::ConfigFiles
- Inherits:
-
Struct
- Object
- Struct
- Dpl::ConfigFile::ConfigFiles
- Defined in:
- lib/dpl/helper/config_file.rb
Instance Attribute Summary collapse
-
#opts ⇒ Object
Returns the value of attribute opts.
-
#paths ⇒ Object
Returns the value of attribute paths.
Instance Method Summary collapse
Instance Attribute Details
#opts ⇒ Object
Returns the value of attribute opts
26 27 28 |
# File 'lib/dpl/helper/config_file.rb', line 26 def opts @opts end |
#paths ⇒ Object
Returns the value of attribute paths
26 27 28 |
# File 'lib/dpl/helper/config_file.rb', line 26 def paths @paths end |
Instance Method Details
#config ⇒ Object
27 28 29 |
# File 'lib/dpl/helper/config_file.rb', line 27 def config paths.map { |path| parse(path) }.inject(&:merge) || {} end |
#parse(path) ⇒ Object
31 32 33 34 35 36 |
# File 'lib/dpl/helper/config_file.rb', line 31 def parse(path) str = File.exists?(path) ? File.read(path) : '' opts = str.lines.select { |line| line.include?('=') }.map(&:strip) opts = opts.map { |pair| pair.split('=', 2) }.to_h opts.map { |key, value| [strip_prefix(key).to_sym, value] }.to_h end |
#strip_prefix(str) ⇒ Object
38 39 40 |
# File 'lib/dpl/helper/config_file.rb', line 38 def strip_prefix(str) opts[:prefix] ? str.sub(/^#{opts[:prefix]}[\-_]?/, '') : str end |