Class: StaticAssetFinder

Inherits:
Object
  • Object
show all
Defined in:
backend/app/lib/static_asset_finder.rb

Instance Method Summary collapse

Constructor Details

#initialize(base) ⇒ StaticAssetFinder

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.exist?(path) && File.file?(path)}
end

Instance Method Details

#find(query) ⇒ Object

Raises:



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

#find_all(query) ⇒ Object

Raises:



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

#find_by_extension(extension) ⇒ Object



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