Skip to content
Open
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ Gemfile.lock
.env
coverage
tmp
/vendor/
Comment thread
PikachuEXE marked this conversation as resolved.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,13 @@ these locations:

* `~/.gem_release/config.yml`
* `~/.gem_release.yml`
* `$XDG_CONFIG_HOME/.gem_release/config.yml`
* `$XDG_CONFIG_HOME/.gem_release.yml`
* `./.gem_release/config.yml`
* `./.gem_release.yml`

`$XDG_CONFIG_HOME` defaults to `~/.config` if not set.

Config files must be in the [YAML](http://www.yaml.org/) format, and list
options per command. Common options can be set on the root.

Expand Down
4 changes: 4 additions & 0 deletions README.md.erb
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,13 @@ these locations:

* `~/.gem_release/config.yml`
* `~/.gem_release.yml`
* `$XDG_CONFIG_HOME/.gem_release/config.yml`
* `$XDG_CONFIG_HOME/.gem_release.yml`
* `./.gem_release/config.yml`
* `./.gem_release.yml`
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it might be a good time to specify the order (local > XDG > global
Not sure how to word it exactly but since we have 3 places now better to spell it out

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@PikachuEXE, I changed the hardcoded list of config file locations to code execution. Let me know what you think.

Could you also run tests again, please? I find it hard to reproduce locally. Ruby 2.3 is ancient by now. ;)


`$XDG_CONFIG_HOME` defaults to `~/.config` if not set.

Config files must be in the [YAML](http://www.yaml.org/) format, and list
options per command. Common options can be set on the root.

Expand Down
22 changes: 15 additions & 7 deletions lib/gem/release/config/files.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,7 @@ class Config
class Files
include Helper::Hash

PATHS = %w(
./.gem_release/config.yml
./.gem_release.yml
~/.gem_release/config.yml
~/.gem_release.yml
)
FILES = %w[.gem_release/config.yml .gem_release.yml]

def load
return {} unless path
Expand All @@ -26,9 +21,22 @@ def path
end

def paths
paths = PATHS.map { |path| File.expand_path(path) }
paths = combine_paths.map { |path| File.expand_path(path) }
paths.select { |path| File.exist?(path) }
end

def xdg_config_home
home_config = File.join(ENV.fetch('HOME'), '.config')
ENV.fetch('XDG_CONFIG_HOME', home_config)
end

def combine_paths
folders = ['./', xdg_config_home, '~/']

folders.product(FILES).map do |folder, file|
File.join(folder, file)
end
end
end
end
end
Expand Down
36 changes: 36 additions & 0 deletions spec/gem/release/config_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
describe Gem::Release::Config do
let(:global) { { bump: { commit: false }, tag: { push: false }, quiet: true } }
let(:local) { { bump: { commit: true, push: true }, quiet: false } }
let(:xdg_config) { { quiet: true, release: { host: 'https://example.com' } } }

subject { described_class.new.opts }

Expand Down Expand Up @@ -37,6 +38,41 @@
before { write './.gem_release.yml', '' }
it { should eq({}) }
end

describe 'XDG_CONFIG_HOME' do
describe 'default' do
before { write File.join(ENV.fetch('HOME'), '.config/.gem_release.yml'), YAML.dump(xdg_config) }
it { should eq xdg_config }
end

describe 'set to ~/.my-little-config' do
env XDG_CONFIG_HOME: '~/.my-little-config'
before { write '~/.my-little-config/.gem_release.yml', YAML.dump(xdg_config) }
it { should eq xdg_config }
end
end

describe 'all three ./.gem_release.yml, XDG_CONFIG_HOME, and ~/.gem_release.yml' do
before { write './.gem_release.yml', YAML.dump(local) }
env XDG_CONFIG_HOME: '~/.my-little-config'
before { write '~/.my-little-config/.gem_release.yml', YAML.dump(xdg_config) }
before { write '~/.gem_release.yml', YAML.dump(global) }
it { should eq local }
end

describe 'both XDG_CONFIG_HOME and ~/.gem_release.yml' do
describe 'XDG_CONFIG_HOME default' do
before { write File.join(ENV.fetch('HOME'), '.config/.gem_release.yml'), YAML.dump(xdg_config) }
before { write '~/.gem_release.yml', YAML.dump(global) }
it { should eq xdg_config }
end
describe 'XDG_CONFIG_HOME set to ~/.my-little-config' do
env XDG_CONFIG_HOME: '~/.my-little-config'
before { write '~/.my-little-config/.gem_release.yml', YAML.dump(xdg_config) }
before { write '~/.gem_release.yml', YAML.dump(global) }
it { should eq xdg_config }
end
end
end

describe 'both env and files' do
Expand Down
Loading