Class: Isomorfeus::AssetManager::Portfolio

Inherits:
Object
  • Object
show all
Defined in:
lib/isomorfeus/asset_manager/portfolio.rb

Class Method Summary collapse

Class Method Details

.get_load_path_entries(path, filter) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/isomorfeus/asset_manager/portfolio.rb', line 4

def self.get_load_path_entries(path, filter)
  path_entries = []
  return [] unless Dir.exist?(path)
  dir_entries = Dir.entries(path)
  dir_entries.each do |entry|
    next if entry == '.'
    next if entry == '..'
    next unless entry
    absolute_path = File.join(path, entry)
    if File.directory?(absolute_path)
      more_path_entries = get_load_path_entries(absolute_path, filter)
      path_entries.push(*more_path_entries) if more_path_entries.size > 0
    elsif (absolute_path.end_with?('.rb') || absolute_path.end_with?('.js')) && File.file?(absolute_path)
      push_entry = true
      if filter && filter.size > 0
        filter.each do |filter_entry|
          push_entry = false if absolute_path.end_with?(filter_entry)
        end
      end
      path_entries.push(absolute_path) if push_entry
    end
  end
  path_entries
end

.get_load_paths_json(*filter) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/isomorfeus/asset_manager/portfolio.rb', line 29

def self.get_load_paths_json(*filter)
  cwd = Dir.pwd

  load_paths = Opal.paths.uniq
  load_path_entries = []

  load_paths.each do |path|
    next if path.start_with?(cwd)
    more_path_entries = get_load_path_entries(path, filter)
    load_path_entries.push(*more_path_entries) if more_path_entries.size > 0
  end

  cache_obj = { 'opal_load_paths' => load_paths, 'opal_load_path_entries' => load_path_entries }
  Oj.dump(cache_obj, mode: :strict, indent: 2)
end