Skip to content

Commit

Permalink
Remove asset paths from eager_load_paths and autoload_paths
Browse files Browse the repository at this point in the history
Remove `app/assets` and `app/javascript` from `eager_load_paths`
and `autoload_paths`.
  • Loading branch information
gmcgibbon committed Nov 9, 2018
1 parent e0f82a0 commit cffbf73
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 10 deletions.
4 changes: 4 additions & 0 deletions railties/CHANGELOG.md
@@ -1,3 +1,7 @@
* Remove `app/assets` and `app/javascript` from `eager_load_paths` and `autoload_paths`.

*Gannon McGibbon*

* Add JSON support to rails properties route (`/rails/info/properties`).

Now, `Rails::Info` properties may be accessed in JSON format at `/rails/info/properties.json`.
Expand Down
4 changes: 3 additions & 1 deletion railties/lib/rails/engine/configuration.rb
Expand Up @@ -38,7 +38,9 @@ def paths
@paths ||= begin
paths = Rails::Paths::Root.new(@root)

paths.add "app", eager_load: true, glob: "{*,*/concerns}"
paths.add "app", eager_load: true,
glob: "{*,*/concerns}",
exclude: %w(assets javascript)
paths.add "app/assets", glob: "*"
paths.add "app/controllers", eager_load: true
paths.add "app/channels", eager_load: true, glob: "**/*_channel.rb"
Expand Down
28 changes: 19 additions & 9 deletions railties/lib/rails/paths.rb
Expand Up @@ -113,10 +113,11 @@ class Path
attr_accessor :glob

def initialize(root, current, paths, options = {})
@paths = paths
@current = current
@root = root
@glob = options[:glob]
@paths = paths
@current = current
@root = root
@glob = options[:glob]
@exclude = options[:exclude]

options[:autoload_once] ? autoload_once! : skip_autoload_once!
options[:eager_load] ? eager_load! : skip_eager_load!
Expand Down Expand Up @@ -189,13 +190,11 @@ def expanded
raise "You need to set a path root" unless @root.path
result = []

each do |p|
path = File.expand_path(p, @root.path)
each do |path|
path = File.expand_path(path, @root.path)

if @glob && File.directory?(path)
Dir.chdir(path) do
result.concat(Dir.glob(@glob).map { |file| File.join path, file }.sort)
end
result.concat files_in(path)
else
result << path
end
Expand All @@ -222,6 +221,17 @@ def existent_directories
end

alias to_a expanded

private

def files_in(path)
Dir.chdir(path) do
files = Dir.glob(@glob)
files -= @exclude if @exclude
files.map! { |file| File.join(path, file) }
files.sort
end
end
end
end
end
8 changes: 8 additions & 0 deletions railties/test/application/configuration_test.rb
Expand Up @@ -1663,6 +1663,14 @@ def index
assert_kind_of Hash, Rails.application.config.database_configuration
end

test "autoload paths do not include asset paths" do
app "development"
ActiveSupport::Dependencies.autoload_paths.each do |path|
assert_not_operator path, :ends_with?, "app/assets"
assert_not_operator path, :ends_with?, "app/javascript"
end
end

test "raises with proper error message if no database configuration found" do
FileUtils.rm("#{app_path}/config/database.yml")
err = assert_raises RuntimeError do
Expand Down

0 comments on commit cffbf73

Please sign in to comment.