Skip to content

Commit fc635b5

Browse files
committed
Accept a Pathname in Application#config_for
That would make possible to use it with action cable configuration.
1 parent 98087a6 commit fc635b5

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

railties/lib/rails/application.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,11 @@ def message_verifier(verifier_name)
219219
# config.middleware.use ExceptionNotifier, config_for(:exception_notification)
220220
# end
221221
def config_for(name, env: Rails.env)
222-
yaml = Pathname.new("#{paths["config"].existent.first}/#{name}.yml")
222+
if name.is_a?(Pathname)
223+
yaml = name
224+
else
225+
yaml = Pathname.new("#{paths["config"].existent.first}/#{name}.yml")
226+
end
223227

224228
if yaml.exist?
225229
require "erb"

railties/test/application/configuration_test.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1306,6 +1306,21 @@ def index
13061306
assert_equal 'custom key', Rails.application.config.my_custom_config['key']
13071307
end
13081308

1309+
test "config_for use the Pathname object if it is provided" do
1310+
app_file 'config/custom.yml', <<-RUBY
1311+
development:
1312+
key: 'custom key'
1313+
RUBY
1314+
1315+
add_to_config <<-RUBY
1316+
config.my_custom_config = config_for(Pathname.new(Rails.root.join("config/custom.yml")))
1317+
RUBY
1318+
1319+
app 'development'
1320+
1321+
assert_equal 'custom key', Rails.application.config.my_custom_config['key']
1322+
end
1323+
13091324
test "config_for raises an exception if the file does not exist" do
13101325
add_to_config <<-RUBY
13111326
config.my_custom_config = config_for('custom')

0 commit comments

Comments
 (0)