Skip to content

Commit

Permalink
Accept a Pathname in Application#config_for
Browse files Browse the repository at this point in the history
That would make possible to use it with action cable configuration.
  • Loading branch information
rafaelfranca committed Dec 15, 2015
1 parent 98087a6 commit fc635b5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
6 changes: 5 additions & 1 deletion railties/lib/rails/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,11 @@ def message_verifier(verifier_name)
# 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"
Expand Down
15 changes: 15 additions & 0 deletions railties/test/application/configuration_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1306,6 +1306,21 @@ def index
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')
Expand Down

0 comments on commit fc635b5

Please sign in to comment.