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
- KNOWN_KEYS =
%w[clone_root editor ai_tool comment_on_fix].freeze
Class Method Summary collapse
Instance Method Summary collapse
- #ai_tool ⇒ Object
- #clone_root ⇒ Object
-
#comment_on_fix?(repo = nil) ⇒ Boolean
Returns whether ‘fix` should post a “working on this” comment.
- #editor ⇒ 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.
13 14 15 16 |
# File 'lib/gem_contribute/config.rb', line 13 def initialize(path: self.class.default_path) @path = path @data = load_file end |
Class Method Details
.default_path ⇒ Object
54 55 56 57 |
# File 'lib/gem_contribute/config.rb', line 54 def self.default_path base = ENV.fetch("XDG_CONFIG_HOME", File.("~/.config")) File.join(base, "gem-contribute", "config.yml") end |
Instance Method Details
#ai_tool ⇒ Object
27 28 29 |
# File 'lib/gem_contribute/config.rb', line 27 def ai_tool @data["ai_tool"] end |
#clone_root ⇒ Object
18 19 20 21 |
# File 'lib/gem_contribute/config.rb', line 18 def clone_root raw = @data["clone_root"] raw ? File.(raw) : nil end |
#comment_on_fix?(repo = nil) ⇒ Boolean
Returns whether ‘fix` should post a “working on this” comment. Pass a repo (`“owner/repo”`) to check the per-repo override; without a repo, returns the global default. Default is true when unset.
34 35 36 37 38 39 40 |
# File 'lib/gem_contribute/config.rb', line 34 def comment_on_fix?(repo = nil) overrides = @data["comment_on_fix_overrides"] return truthy?(overrides[repo]) if repo && overrides.is_a?(Hash) && overrides.key?(repo) raw = @data["comment_on_fix"] raw.nil? || truthy?(raw) end |
#editor ⇒ Object
23 24 25 |
# File 'lib/gem_contribute/config.rb', line 23 def editor @data["editor"] end |
#set(key, value) ⇒ Object
42 43 44 45 46 47 48 |
# File 'lib/gem_contribute/config.rb', line 42 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
50 51 52 |
# File 'lib/gem_contribute/config.rb', line 50 def to_h @data.dup end |