Class: GemContribute::Config
- Inherits:
-
Object
- Object
- GemContribute::Config
- Defined in:
- lib/gem_contribute/config.rb
Overview
Reads and writes ~/.config/gem-contribute/config.yml. Honors XDG_CONFIG_HOME so tests stay hermetic and unusual layouts work. Missing or corrupt files are treated as an empty config (no crash).
Constant Summary collapse
- DEFAULT_CLONE_ROOT =
File.("~/code/oss")
- KNOWN_KEYS =
%w[clone_root].freeze
Class Method Summary collapse
Instance Method Summary collapse
- #clone_root ⇒ Object
-
#initialize(path: self.class.default_path) ⇒ Config
constructor
A new instance of Config.
- #set(key, value) ⇒ Object
- #to_h ⇒ Object
Constructor Details
#initialize(path: self.class.default_path) ⇒ Config
Returns a new instance of Config.
15 16 17 18 |
# File 'lib/gem_contribute/config.rb', line 15 def initialize(path: self.class.default_path) @path = path @data = load_file end |
Class Method Details
.default_path ⇒ Object
37 38 39 40 |
# File 'lib/gem_contribute/config.rb', line 37 def self.default_path base = ENV.fetch("XDG_CONFIG_HOME", File.("~/.config")) File.join(base, "gem-contribute", "config.yml") end |
Instance Method Details
#clone_root ⇒ Object
20 21 22 23 |
# File 'lib/gem_contribute/config.rb', line 20 def clone_root raw = @data["clone_root"] raw ? File.(raw) : DEFAULT_CLONE_ROOT end |
#set(key, value) ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/gem_contribute/config.rb', line 25 def set(key, value) raise ArgumentError, "unknown config key #{key.inspect}. Known keys: #{KNOWN_KEYS.join(", ")}" \ unless KNOWN_KEYS.include?(key) @data[key] = value write_file end |
#to_h ⇒ Object
33 34 35 |
# File 'lib/gem_contribute/config.rb', line 33 def to_h @data.dup end |