Skip to content

Commit 0194f2b

Browse files
vadtelpkuczynski
andauthored
Prevent name collision with private methods from ancestors (#351)
* 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 <[email protected]>
1 parent 96132ba commit 0194f2b

File tree

4 files changed

+20
-1
lines changed

4 files changed

+20
-1
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,14 @@
22

33
## Next
44

5+
### New features
6+
57
* Allow to use custom filename && directory name to store configs ([#341](https://github.com/rubyconfig/config/pull/341))
68

9+
### Bug fixes
10+
11+
* Prevent name collision with private methods from ancestors ([#351](https://github.com/rubyconfig/config/pull/351))
12+
713
## 5.1.0
814

915
* Fix conflicts with Rails 7 active_support methods ([#347](https://github.com/rubyconfig/config/pull/347))

lib/config/options.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ def merge!(hash)
122122
def [](param)
123123
return super if SETTINGS_RESERVED_NAMES.include?(param)
124124
return super if RAILS_RESERVED_NAMES.include?(param)
125-
send("#{param}")
125+
public_send("#{param}")
126126
end
127127

128128
def []=(param, value)

spec/fixtures/reserved_keywords.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ max: kumquat
77
min: fig
88
exit!: taro
99
table: strawberry
10+
lambda: proc
11+
proc: lambda
1012

1113
# Rails 7.* reserved keywords
1214
minimum: 10

spec/options_spec.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
expect(config.min).to eq('fig')
2020
expect(config.exit!).to eq('taro')
2121
expect(config.table).to eq('strawberry')
22+
expect(config.lambda).to eq('proc')
23+
expect(config.proc).to eq('lambda')
2224
end
2325

2426
it 'should allow to access them using [] operator' do
@@ -30,6 +32,8 @@
3032
expect(config['min']).to eq('fig')
3133
expect(config['exit!']).to eq('taro')
3234
expect(config['table']).to eq('strawberry')
35+
expect(config['lambda']).to eq('proc')
36+
expect(config['proc']).to eq('lambda')
3337

3438
expect(config[:select]).to eq('apple')
3539
expect(config[:collect]).to eq('banana')
@@ -39,6 +43,8 @@
3943
expect(config[:min]).to eq('fig')
4044
expect(config[:exit!]).to eq('taro')
4145
expect(config[:table]).to eq('strawberry')
46+
expect(config[:lambda]).to eq('proc')
47+
expect(config[:proc]).to eq('lambda')
4248
end
4349

4450
context 'when Settings file is using keywords reserved by Rails 7' do
@@ -64,14 +70,19 @@
6470
it 'should allow to access them via object member notation' do
6571
expect(config.select).to be_nil
6672
expect(config.table).to be_nil
73+
expect(config.exit!).to be_nil
6774
end
6875

6976
it 'should allow to access them using [] operator' do
7077
expect(config['select']).to be_nil
7178
expect(config['table']).to be_nil
79+
expect(config['lambda']).to be_nil
80+
expect(config['proc']).to be_nil
81+
expect(config['exit!']).to be_nil
7282

7383
expect(config[:select]).to be_nil
7484
expect(config[:table]).to be_nil
85+
expect(config[:exit!]).to be_nil
7586
end
7687
end
7788
end

0 commit comments

Comments
 (0)