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

feat: Find all asset by a regexp filemask or a filepath #698

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Get upgrade notes from Sprockets 3.x to 4.x at https://github.com/rails/sprocket
## Master

- Remove remaining support for Ruby < 2.4.[#672](https://github.com/rails/sprockets/pull/672)
- Find all asset by a regexp filemask or a filepath.[#698](https://github.com/rails/sprockets/pull/698)

## 4.0.2

Expand Down
19 changes: 19 additions & 0 deletions lib/sprockets/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,25 @@ def find_asset!(*args)
end
end

# Find all asset by a regexp filemask or a filepath.
def find_all_assets(*args, &block)
paths = config[:paths]

args.each do |arg|
if arg.is_a?(Regexp)
paths.each do |path|
files = Dir["#{path}/*"].select {|file| arg =~ file }

files.each do |file|
find_all_linked_assets(file, &block)
end
end
else
find_all_linked_assets(arg, &block)
end
end
end

# Pretty inspect
def inspect
"#<#{self.class}:0x#{object_id.to_s(16)} " +
Expand Down
2 changes: 1 addition & 1 deletion lib/sprockets/manifest.rb
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def find(*args)
environment = self.environment.cached
promises = args.flatten.map do |path|
Concurrent::Promise.execute(executor: executor) do
environment.find_all_linked_assets(path) do |asset|
environment.find_all_assets(path) do |asset|
yield asset
end
end
Expand Down