Skip to content

Commit a533cf8

Browse files
authored
Merge pull request #385 from DannyBen/add/bashly-settings-filename-support
Allow using `bashly-settings.yml` instead of `settings.yml`
2 parents 5410200 + 16ba317 commit a533cf8

File tree

3 files changed

+58
-9
lines changed

3 files changed

+58
-9
lines changed

lib/bashly/settings.rb

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@ def strict
5656
end
5757

5858
def strict_string
59-
if Settings.strict.is_a? String
60-
Settings.strict
61-
elsif Settings.strict
59+
if strict.is_a? String
60+
strict
61+
elsif strict
6262
'set -euo pipefail'
6363
else
6464
'set -e'
@@ -101,7 +101,13 @@ def user_settings
101101
end
102102

103103
def user_settings_path
104-
ENV['BASHLY_SETTINGS_PATH'] || 'settings.yml'
104+
@user_settings_path ||= if ENV['BASHLY_SETTINGS_PATH']
105+
ENV['BASHLY_SETTINGS_PATH']
106+
elsif File.exist? 'bashly-settings.yml'
107+
'bashly-settings.yml'
108+
else
109+
'settings.yml'
110+
end
105111
end
106112

107113
def defsult_settings

spec/bashly/settings_spec.rb

Lines changed: 44 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,56 @@
11
require 'spec_helper'
22

33
describe Settings do
4-
subject { described_class }
4+
subject { BaselineSettings.clone }
55

66
describe 'standard value' do
77
it 'returns a predefined default value' do
88
expect(subject.tab_indent).to be false
99
end
1010

11+
context 'when settings.yml exists' do
12+
before do
13+
reset_tmp_dir
14+
File.write 'spec/tmp/settings.yml', 'source_dir: somedir'
15+
subject.source_dir = nil
16+
end
17+
18+
it 'returns the value from the settings file' do
19+
Dir.chdir 'spec/tmp' do
20+
expect(subject.source_dir).to eq 'somedir'
21+
end
22+
end
23+
end
24+
25+
context 'when bashly-settings.yml exists' do
26+
before do
27+
reset_tmp_dir
28+
File.write 'spec/tmp/bashly-settings.yml', 'source_dir: somedir'
29+
subject.source_dir = nil
30+
end
31+
32+
it 'returns the value from the settings file' do
33+
Dir.chdir 'spec/tmp' do
34+
expect(subject.source_dir).to eq 'somedir'
35+
end
36+
end
37+
end
38+
39+
context 'when BASHLY_SETTINGS_PATH is set' do
40+
before do
41+
reset_tmp_dir
42+
File.write 'spec/tmp/my-settings.yml', 'source_dir: from-var'
43+
ENV['BASHLY_SETTINGS_PATH'] = 'spec/tmp/my-settings.yml'
44+
subject.source_dir = nil
45+
end
46+
47+
after { ENV['BASHLY_SETTINGS_PATH'] = nil }
48+
49+
it 'returns the value from the settings file' do
50+
expect(subject.source_dir).to eq 'from-var'
51+
end
52+
end
53+
1154
context 'when its corresponding env var is set' do
1255
original_value = ENV['BASHLY_TAB_INDENT']
1356

@@ -57,10 +100,6 @@
57100
end
58101

59102
describe 'strict_string' do
60-
original_value = described_class.strict
61-
62-
after { subject.strict = original_value }
63-
64103
context 'when strict is true' do
65104
before { subject.strict = true }
66105

spec/spec_helper.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@
3434
Settings.env = :development
3535
reset_tmp_dir
3636

37+
# This is used in the Settings spec, to ensure we are working with an
38+
# eigenclass that has a known state
39+
BaselineSettings = Settings.clone
40+
3741
# Consistent Colsole output (for rspec_fixtures)
3842
ENV['TTY'] = 'off'
3943
ENV['COLUMNS'] = '80'

0 commit comments

Comments
 (0)