Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactoring the expanded method in the paths module. #10018

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 4 additions & 6 deletions railties/lib/rails/paths.rb
Expand Up @@ -183,22 +183,20 @@ def to_ary
# Expands all paths against the root and return all unique values.
def expanded
raise "You need to set a path root" unless @root.path
result = []

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

if @glob && File.directory?(path)
Dir.chdir(path) do
result.concat(Dir.glob(@glob).map { |file| File.join path, file }.sort)
Dir.glob(@glob).map { |file| File.join path, file }
end
else
result << path
path
end
end

result.uniq!
result
result.flatten.uniq
end

# Returns all expanded paths but only if they exist in the filesystem.
Expand Down