Skip to content

Commit d8d1319

Browse files
authored
Address edge case with table config param (#339)
1 parent 775895c commit d8d1319

3 files changed

Lines changed: 26 additions & 3 deletions

File tree

lib/config/options.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ def merge!(hash)
112112
end
113113

114114
# Some keywords that don't play nicely with OpenStruct
115-
SETTINGS_RESERVED_NAMES = %w[select collect test count zip min max exit!].freeze
115+
SETTINGS_RESERVED_NAMES = %w[select collect test count zip min max exit! table].freeze
116116

117117
# An alternative mechanism for property access.
118118
# This let's you do foo['bar'] along with foo.bar.
@@ -132,11 +132,11 @@ def []=(param, value)
132132
end
133133

134134
def key?(key)
135-
table.key?(key)
135+
@table.key?(key)
136136
end
137137

138138
def has_key?(key)
139-
table.has_key?(key)
139+
@table.has_key?(key)
140140
end
141141

142142
def method_missing(method_name, *args)

spec/fixtures/reserved_keywords.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ zip: cherry
55
max: kumquat
66
min: fig
77
exit!: taro
8+
table: strawberry

spec/options_spec.rb

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
expect(config.max).to eq('kumquat')
1919
expect(config.min).to eq('fig')
2020
expect(config.exit!).to eq('taro')
21+
expect(config.table).to eq('strawberry')
2122
end
2223

2324
it 'should allow to access them using [] operator' do
@@ -28,6 +29,7 @@
2829
expect(config['max']).to eq('kumquat')
2930
expect(config['min']).to eq('fig')
3031
expect(config['exit!']).to eq('taro')
32+
expect(config['table']).to eq('strawberry')
3133

3234
expect(config[:select]).to eq('apple')
3335
expect(config[:collect]).to eq('banana')
@@ -36,6 +38,26 @@
3638
expect(config[:max]).to eq('kumquat')
3739
expect(config[:min]).to eq('fig')
3840
expect(config[:exit!]).to eq('taro')
41+
expect(config[:table]).to eq('strawberry')
42+
end
43+
44+
context 'when empty' do
45+
let(:config) do
46+
Config.load_files("#{fixture_path}/empty1.yml")
47+
end
48+
49+
it 'should allow to access them via object member notation' do
50+
expect(config.select).to be_nil
51+
expect(config.table).to be_nil
52+
end
53+
54+
it 'should allow to access them using [] operator' do
55+
expect(config['select']).to be_nil
56+
expect(config['table']).to be_nil
57+
58+
expect(config[:select]).to be_nil
59+
expect(config[:table]).to be_nil
60+
end
3961
end
4062
end
4163

0 commit comments

Comments
 (0)