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
28 29 30 |
# File 'lib/dpl/helper/config_file.rb', line 28 def opts @opts end |
#paths ⇒ Object
Returns the value of attribute paths
28 29 30 |
# File 'lib/dpl/helper/config_file.rb', line 28 def paths @paths end |
Instance Method Details
#config ⇒ Object
29 30 31 |
# File 'lib/dpl/helper/config_file.rb', line 29 def config paths.map { |path| parse(path) }.inject(&:merge) || {} end |
#parse(path) ⇒ Object
33 34 35 36 37 38 |
# File 'lib/dpl/helper/config_file.rb', line 33 def parse(path) str = File.exist?(path) ? File.read(path) : '' opts = str.lines.select { |line| line.include?('=') }.map(&:strip) opts = opts.map { |pair| pair.split('=', 2) }.to_h opts.transform_keys { |key| strip_prefix(key).to_sym } end |
#strip_prefix(str) ⇒ Object
40 41 42 |
# File 'lib/dpl/helper/config_file.rb', line 40 def strip_prefix(str) opts[:prefix] ? str.sub(/^#{opts[:prefix]}[-_]?/, '') : str end |