From ee4a016748f539b7c13a4056ad22ee713d4a7582 Mon Sep 17 00:00:00 2001 From: Vadim Teltevski Date: Tue, 13 Feb 2024 22:53:48 +0100 Subject: [PATCH 1/5] Fix some problem of name collision with name of private method from ancestors --- lib/config/options.rb | 2 +- spec/fixtures/reserved_keywords.yml | 2 ++ spec/options_spec.rb | 8 ++++++++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/config/options.rb b/lib/config/options.rb index 08f3d409..07944b73 100644 --- a/lib/config/options.rb +++ b/lib/config/options.rb @@ -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) diff --git a/spec/fixtures/reserved_keywords.yml b/spec/fixtures/reserved_keywords.yml index 134941b1..1346fe73 100644 --- a/spec/fixtures/reserved_keywords.yml +++ b/spec/fixtures/reserved_keywords.yml @@ -7,6 +7,8 @@ max: kumquat min: fig exit!: taro table: strawberry +lambda: proc +proc: lambda # Rails 7.* reserved keywords minimum: 10 diff --git a/spec/options_spec.rb b/spec/options_spec.rb index ff65cc61..11e5ccf6 100644 --- a/spec/options_spec.rb +++ b/spec/options_spec.rb @@ -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 @@ -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') @@ -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 @@ -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 From 085465c543963e2aba30dcfc9da915180f24cbff Mon Sep 17 00:00:00 2001 From: Vadim Teltevski Date: Wed, 14 Feb 2024 12:51:46 +0100 Subject: [PATCH 2/5] Remove unnecessary keyword --- lib/config/options.rb | 2 +- spec/options_spec.rb | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/config/options.rb b/lib/config/options.rb index 07944b73..972135d6 100644 --- a/lib/config/options.rb +++ b/lib/config/options.rb @@ -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! table].freeze + SETTINGS_RESERVED_NAMES = %w[select collect test count zip min max table].freeze # Some keywords that don't play nicely with Rails 7.* RAILS_RESERVED_NAMES = %w[maximum minimum].freeze diff --git a/spec/options_spec.rb b/spec/options_spec.rb index 11e5ccf6..fbf0b0ca 100644 --- a/spec/options_spec.rb +++ b/spec/options_spec.rb @@ -70,6 +70,7 @@ 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 @@ -77,9 +78,11 @@ 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 From 56022eb7a252029bcf20f4a1bcbe3742640c4a6e Mon Sep 17 00:00:00 2001 From: Piotr Kuczynski Date: Sun, 18 Feb 2024 20:33:12 +0100 Subject: [PATCH 3/5] Update CHANGELOG.md --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8f51ef2d..742a9a2f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## Next + +* 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)) From 4d1aa162957adaeab5eb02edae518d88beeca452 Mon Sep 17 00:00:00 2001 From: Piotr Kuczynski Date: Sun, 18 Feb 2024 20:42:54 +0100 Subject: [PATCH 4/5] Update CHANGELOG.md --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6e23009f..328b63f1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,12 @@ ## 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 From ef3a3ef0f87678eaaf2f4bdce310f920dbed4ed7 Mon Sep 17 00:00:00 2001 From: Vadim Teltevski Date: Mon, 19 Feb 2024 20:57:22 +0100 Subject: [PATCH 5/5] Return exit --- lib/config/options.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/config/options.rb b/lib/config/options.rb index 972135d6..07944b73 100644 --- a/lib/config/options.rb +++ b/lib/config/options.rb @@ -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 table].freeze + SETTINGS_RESERVED_NAMES = %w[select collect test count zip min max exit! table].freeze # Some keywords that don't play nicely with Rails 7.* RAILS_RESERVED_NAMES = %w[maximum minimum].freeze