Skip to content

Commit

Permalink
Prevent name collision with private methods from ancestors (#351)
Browse files Browse the repository at this point in the history
* Fix some problem of name collision with name of private method from ancestors

* Remove unnecessary keyword

* Update CHANGELOG.md

* Update CHANGELOG.md

* Return exit

---------

Co-authored-by: Piotr Kuczynski <piotr.kuczynski@gmail.com>
  • Loading branch information
vadtel and pkuczynski authored Mar 2, 2024
1 parent 96132ba commit 0194f2b
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 1 deletion.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,14 @@

## Next

### New features

* Allow to use custom filename && directory name to store configs ([#341](https://github.com/rubyconfig/config/pull/341))

### Bug fixes

* Prevent name collision with private methods from ancestors ([#351](https://github.com/rubyconfig/config/pull/351))

## 5.1.0

* Fix conflicts with Rails 7 active_support methods ([#347](https://github.com/rubyconfig/config/pull/347))
Expand Down
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
11 changes: 11 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 All @@ -64,14 +70,19 @@
it 'should allow to access them via object member notation' do
expect(config.select).to be_nil
expect(config.table).to be_nil
expect(config.exit!).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['lambda']).to be_nil
expect(config['proc']).to be_nil
expect(config['exit!']).to be_nil

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

0 comments on commit 0194f2b

Please sign in to comment.