File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11# Changelog
22
3+ ## Next
4+
5+ * Fix conflicts with Rails 7 active_support methods ([ #347 ] ( https://github.com/rubyconfig/config/pull/339 ) )
6+
37## 5.0.0
48
59### BREAKING CHANGES
Original file line number Diff line number Diff line change @@ -114,10 +114,14 @@ def merge!(hash)
114114 # Some keywords that don't play nicely with OpenStruct
115115 SETTINGS_RESERVED_NAMES = %w[ select collect test count zip min max exit! table ] . freeze
116116
117+ # Some keywords that don't play nicely with Rails 7.*
118+ RAILS_RESERVED_NAMES = %w[ maximum minimum ] . freeze
119+
117120 # An alternative mechanism for property access.
118121 # This let's you do foo['bar'] along with foo.bar.
119122 def []( param )
120123 return super if SETTINGS_RESERVED_NAMES . include? ( param )
124+ return super if RAILS_RESERVED_NAMES . include? ( param )
121125 send ( "#{ param } " )
122126 end
123127
@@ -131,6 +135,12 @@ def []=(param, value)
131135 end
132136 end
133137
138+ RAILS_RESERVED_NAMES . each do |name |
139+ define_method name do
140+ self [ name ]
141+ end
142+ end
143+
134144 def key? ( key )
135145 @table . key? ( key )
136146 end
Original file line number Diff line number Diff line change 1+ # OpenStruct reserved keywords
12select : apple
23collect : banana
34count : lemon
@@ -6,3 +7,7 @@ max: kumquat
67min : fig
78exit! : taro
89table : strawberry
10+
11+ # Rails 7.* reserved keywords
12+ minimum : 10
13+ maximum : 20
Original file line number Diff line number Diff line change 4141 expect ( config [ :table ] ) . to eq ( 'strawberry' )
4242 end
4343
44+ context 'when Settings file is using keywords reserved by Rails 7' do
45+ it 'should allow to access them via object member notation' do
46+ expect ( config . maximum ) . to eq ( 20 )
47+ expect ( config . minimum ) . to eq ( 10 )
48+ end
49+
50+ it 'should allow to access them using [] operator' do
51+ expect ( config [ 'maximum' ] ) . to eq ( 20 )
52+ expect ( config [ 'minimum' ] ) . to eq ( 10 )
53+
54+ expect ( config [ :maximum ] ) . to eq ( 20 )
55+ expect ( config [ :minimum ] ) . to eq ( 10 )
56+ end
57+ end
58+
4459 context 'when empty' do
4560 let ( :config ) do
4661 Config . load_files ( "#{ fixture_path } /empty1.yml" )
You can’t perform that action at this time.
0 commit comments