Skip to content

Commit

Permalink
Address edge case with table config param (#339)
Browse files Browse the repository at this point in the history
  • Loading branch information
krasnoukhov authored Jun 15, 2023
1 parent 775895c commit d8d1319
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/config/options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def merge!(hash)
end

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

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

def key?(key)
table.key?(key)
@table.key?(key)
end

def has_key?(key)
table.has_key?(key)
@table.has_key?(key)
end

def method_missing(method_name, *args)
Expand Down
1 change: 1 addition & 0 deletions spec/fixtures/reserved_keywords.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ zip: cherry
max: kumquat
min: fig
exit!: taro
table: strawberry
22 changes: 22 additions & 0 deletions spec/options_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
expect(config.max).to eq('kumquat')
expect(config.min).to eq('fig')
expect(config.exit!).to eq('taro')
expect(config.table).to eq('strawberry')
end

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

expect(config[:select]).to eq('apple')
expect(config[:collect]).to eq('banana')
Expand All @@ -36,6 +38,26 @@
expect(config[:max]).to eq('kumquat')
expect(config[:min]).to eq('fig')
expect(config[:exit!]).to eq('taro')
expect(config[:table]).to eq('strawberry')
end

context 'when empty' do
let(:config) do
Config.load_files("#{fixture_path}/empty1.yml")
end

it 'should allow to access them via object member notation' do
expect(config.select).to be_nil
expect(config.table).to be_nil
end

it 'should allow to access them using [] operator' do
expect(config['select']).to be_nil
expect(config['table']).to be_nil

expect(config[:select]).to be_nil
expect(config[:table]).to be_nil
end
end
end

Expand Down

0 comments on commit d8d1319

Please sign in to comment.