Class: StaticAssetFinder
- Inherits:
-
Object
- Object
- StaticAssetFinder
- Defined in:
- backend/app/lib/static_asset_finder.rb
Instance Method Summary (collapse)
-
- (Object) find(query)
-
- (Object) find_all(query)
-
- (Object) find_by_extension(extension)
-
- (StaticAssetFinder) initialize(base)
constructor
A new instance of StaticAssetFinder.
Constructor Details
- (StaticAssetFinder) initialize(base)
Returns a new instance of StaticAssetFinder
3 4 5 6 7 8 |
# File 'backend/app/lib/static_asset_finder.rb', line 3 def initialize(base) static_dir = File.join(ASUtils.find_base_directory, base) @valid_paths = Dir[File.join(static_dir, "**", "*")]. select {|path| File.exists?(path) && File.file?(path)} end |
Instance Method Details
- (Object) find(query)
11 12 13 14 15 16 17 18 19 20 |
# File 'backend/app/lib/static_asset_finder.rb', line 11 def find(query) match = if query && !query.empty? @valid_paths.find {|path| path.end_with?(query)} end raise NotFoundException.new("File not found: #{query} in #{@valid_paths}") unless match match end |
- (Object) find_all(query)
22 23 24 25 26 27 28 29 30 31 |
# File 'backend/app/lib/static_asset_finder.rb', line 22 def find_all(query) match = if query && !query.empty? @valid_paths.select {|path| path.end_with?(query)} end raise NotFoundException.new("File not found: #{query} in #{@valid_paths}") unless match match end |
- (Object) find_by_extension(extension)
34 35 36 |
# File 'backend/app/lib/static_asset_finder.rb', line 34 def find_by_extension(extension) @valid_paths.select { |path| File.extname(path) == extension } end |