Module: AbideDevUtils::Config
- Included in:
- Abide::CLI::AbideCommand
- Defined in:
- lib/abide_dev_utils/config.rb
Constant Summary collapse
- DEFAULT_PATH =
"#{File.('~')}/.abide_dev.yaml"
Class Method Summary collapse
- .config_section(section, path = DEFAULT_PATH) ⇒ Object
- .fetch(key, default = nil, path = DEFAULT_PATH) ⇒ Object
- .to_h(path = DEFAULT_PATH) ⇒ Object
Instance Method Summary collapse
- #config_section(section, path = DEFAULT_PATH) ⇒ Object
- #fetch(key, default = nil, path = DEFAULT_PATH) ⇒ Object
- #to_h(path = DEFAULT_PATH) ⇒ Object
Class Method Details
.config_section(section, path = DEFAULT_PATH) ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/abide_dev_utils/config.rb', line 20 def self.config_section(section, path = DEFAULT_PATH) h = to_h(path) s = h.fetch(section.to_sym, nil) return {} if s.nil? s.transform_keys(&:to_sym) end |
.fetch(key, default = nil, path = DEFAULT_PATH) ⇒ Object
36 37 38 |
# File 'lib/abide_dev_utils/config.rb', line 36 def self.fetch(key, default = nil, path = DEFAULT_PATH) to_h(path).fetch(key, default) end |
.to_h(path = DEFAULT_PATH) ⇒ Object
9 10 11 12 13 14 |
# File 'lib/abide_dev_utils/config.rb', line 9 def self.to_h(path = DEFAULT_PATH) return {} unless File.file?(path) h = AbideDevUtils::Files::Reader.read(path) h.transform_keys(&:to_sym) end |
Instance Method Details
#config_section(section, path = DEFAULT_PATH) ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/abide_dev_utils/config.rb', line 28 def config_section(section, path = DEFAULT_PATH) h = to_h(path) s = h.fetch(section.to_sym, nil) return {} if s.nil? s.transform_keys(&:to_sym) end |
#fetch(key, default = nil, path = DEFAULT_PATH) ⇒ Object
40 41 42 |
# File 'lib/abide_dev_utils/config.rb', line 40 def fetch(key, default = nil, path = DEFAULT_PATH) to_h(path).fetch(key, default) end |
#to_h(path = DEFAULT_PATH) ⇒ Object
16 17 18 |
# File 'lib/abide_dev_utils/config.rb', line 16 def to_h(path = DEFAULT_PATH) self.class.to_h(path) end |