From fc635b565393bd6b70be4af524934b3ea359e83c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?= Date: Tue, 15 Dec 2015 15:50:56 -0200 Subject: Accept a Pathname in Application#config_for That would make possible to use it with action cable configuration. --- railties/lib/rails/application.rb | 6 +++++- railties/test/application/configuration_test.rb | 15 +++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/lib/rails/application.rb b/railties/lib/rails/application.rb index 77efe3248d..cac31e1eed 100644 --- a/railties/lib/rails/application.rb +++ b/railties/lib/rails/application.rb @@ -219,7 +219,11 @@ module Rails # config.middleware.use ExceptionNotifier, config_for(:exception_notification) # end def config_for(name, env: Rails.env) - yaml = Pathname.new("#{paths["config"].existent.first}/#{name}.yml") + if name.is_a?(Pathname) + yaml = name + else + yaml = Pathname.new("#{paths["config"].existent.first}/#{name}.yml") + end if yaml.exist? require "erb" diff --git a/railties/test/application/configuration_test.rb b/railties/test/application/configuration_test.rb index 25e749ac14..264f254bfe 100644 --- a/railties/test/application/configuration_test.rb +++ b/railties/test/application/configuration_test.rb @@ -1306,6 +1306,21 @@ module ApplicationTests assert_equal 'custom key', Rails.application.config.my_custom_config['key'] end + test "config_for use the Pathname object if it is provided" do + app_file 'config/custom.yml', <<-RUBY + development: + key: 'custom key' + RUBY + + add_to_config <<-RUBY + config.my_custom_config = config_for(Pathname.new(Rails.root.join("config/custom.yml"))) + RUBY + + app 'development' + + assert_equal 'custom key', Rails.application.config.my_custom_config['key'] + end + test "config_for raises an exception if the file does not exist" do add_to_config <<-RUBY config.my_custom_config = config_for('custom') -- cgit v1.2.3