Skip to content

Commit

Permalink
Fix some problem of name collision with name of private method from a…
Browse files Browse the repository at this point in the history
…ncestors
  • Loading branch information
vadtel committed Feb 13, 2024
1 parent f881cd9 commit ee4a016
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/config/options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def merge!(hash)
def [](param)
return super if SETTINGS_RESERVED_NAMES.include?(param)
return super if RAILS_RESERVED_NAMES.include?(param)
send("#{param}")
public_send("#{param}")
end

def []=(param, value)
Expand Down
2 changes: 2 additions & 0 deletions spec/fixtures/reserved_keywords.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ max: kumquat
min: fig
exit!: taro
table: strawberry
lambda: proc
proc: lambda

# Rails 7.* reserved keywords
minimum: 10
Expand Down
8 changes: 8 additions & 0 deletions spec/options_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
expect(config.min).to eq('fig')
expect(config.exit!).to eq('taro')
expect(config.table).to eq('strawberry')
expect(config.lambda).to eq('proc')
expect(config.proc).to eq('lambda')
end

it 'should allow to access them using [] operator' do
Expand All @@ -30,6 +32,8 @@
expect(config['min']).to eq('fig')
expect(config['exit!']).to eq('taro')
expect(config['table']).to eq('strawberry')
expect(config['lambda']).to eq('proc')
expect(config['proc']).to eq('lambda')

expect(config[:select]).to eq('apple')
expect(config[:collect]).to eq('banana')
Expand All @@ -39,6 +43,8 @@
expect(config[:min]).to eq('fig')
expect(config[:exit!]).to eq('taro')
expect(config[:table]).to eq('strawberry')
expect(config[:lambda]).to eq('proc')
expect(config[:proc]).to eq('lambda')
end

context 'when Settings file is using keywords reserved by Rails 7' do
Expand Down Expand Up @@ -69,6 +75,8 @@
it 'should allow to access them using [] operator' do
expect(config['select']).to be_nil
expect(config['table']).to be_nil
expect(config['lambda']).to be_nil
expect(config['proc']).to be_nil

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

0 comments on commit ee4a016

Please sign in to comment.