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
23 24 25 26 27 28 29 |
# File 'lib/abide_dev_utils/config.rb', line 23 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
39 40 41 |
# File 'lib/abide_dev_utils/config.rb', line 39 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 = YAML.safe_load(File.open(path), [Symbol]) h.transform_keys(&:to_sym) end |
Instance Method Details
#config_section(section, path = DEFAULT_PATH) ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/abide_dev_utils/config.rb', line 31 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
43 44 45 |
# File 'lib/abide_dev_utils/config.rb', line 43 def fetch(key, default = nil, path = DEFAULT_PATH) to_h(path).fetch(key, default) end |
#to_h(path = DEFAULT_PATH) ⇒ Object
16 17 18 19 20 21 |
# File 'lib/abide_dev_utils/config.rb', line 16 def to_h(path = DEFAULT_PATH) return {} unless File.file?(path) h = YAML.safe_load(File.open(path), [Symbol]) h.transform_keys(&:to_sym) end |