Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Make Rails.public_path return a Pathname #7825

Merged
merged 1 commit into from

3 participants

@sikachu
Collaborator

I've discussed with @tenderlove earlier, and it seems like it make sense to make Rails.public_path a Pathname, so you can call Pathname methods on it, such as .join. I think this is a useful addition to this method.

@schneems
Collaborator

:+1: looks useful, and seems like Pathname behaves as a string in most circumstances so backwards compatibility wouldn't be an issue.

@rafaelfranca rafaelfranca merged commit 6b802cd into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Oct 3, 2012
  1. @sikachu
This page is out of date. Refresh to see the latest.
2  railties/CHANGELOG.md
@@ -1,5 +1,7 @@
## Rails 4.0.0 (unreleased) ##
+* `Rails.public_path` now returns a Pathname object. *Prem Sichanugrist*
+
* Remove highly uncommon `config.assets.manifest` option for moving the manifest path.
This option is now unsupported in sprockets-rails.
View
2  railties/lib/rails.rb
@@ -127,7 +127,7 @@ def version
end
def public_path
- application && application.paths["public"].first
+ application && Pathname.new(application.paths["public"].first)
end
end
end
View
10 railties/test/application/configuration_test.rb
@@ -139,6 +139,14 @@ def teardown
assert_instance_of Pathname, Rails.root
end
+ test "Rails.public_path should be a Pathname" do
+ add_to_config <<-RUBY
+ config.paths["public"] = "somewhere"
+ RUBY
+ require "#{app_path}/config/environment"
+ assert_instance_of Pathname, Rails.public_path
+ end
+
test "initialize an eager loaded, cache classes app" do
add_to_config <<-RUBY
config.eager_load = true
@@ -227,7 +235,7 @@ def assert_utf8
RUBY
require "#{app_path}/config/application"
- assert_equal File.join(app_path, "somewhere"), Rails.public_path
+ assert_equal Pathname.new(app_path).join("somewhere"), Rails.public_path
end
test "config.secret_token is sent in env" do
Something went wrong with that request. Please try again.