Module: StaticPaths::Finders

Includes:
Enumerable
Defined in:
lib/static_paths/finders.rb

Instance Method Summary

Instance Method Details

- (Array<String>) all_static_dirs(path)

Finds all occurrences of a given directory path, within all static directories.

Parameters:

  • (String) path — The directory path to search for.

Returns:

  • (Array<String>) — The occurrences of the given directory path within all static directories.


170
171
172
# File 'lib/static_paths/finders.rb', line 170

def all_static_dirs(path)
  Enumerator.new(self,:each_static_dir,path).to_a
end

- (Array<String>) all_static_files(path)

Finds all occurrences of a given file path, within all static directories.

Parameters:

  • (String) path — The file path to search for.

Returns:

  • (Array<String>) — The occurrences of the given file path within all static directories.


132
133
134
# File 'lib/static_paths/finders.rb', line 132

def all_static_files(path)
  Enumerator.new(self,:each_static_file,path).to_a
end

- (Array<String>) all_static_paths(path)

Finds all occurrences of a given path, within all static directories.

Parameters:

  • (String) path — The path to search for.

Returns:

  • (Array<String>) — The occurrences of the given path within all static directories.


93
94
95
# File 'lib/static_paths/finders.rb', line 93

def all_static_paths(path)
  Enumerator.new(self,:each_static_path,path).to_a
end

- (Array<String>) each_static_dir(path, &block) {|static_dir| ... }

Finds all occurrences of a given directory path, within all static directories.

Parameters:

  • (String) path — The directory path to search for.

Yields:

  • (static_dir) — If a block is given, it will be passed every found path.

Yield Parameters:

  • (String) static_dir — The path of a directory within a static directory.

Returns:

  • (Array<String>) — The occurrences of the given directory path within all static directories.


153
154
155
156
157
# File 'lib/static_paths/finders.rb', line 153

def each_static_dir(path,&block)
  each_static_path(path) do |full_path|
    block.call(full_path) if File.directory?(full_path)
  end
end

- (Array<String>) each_static_file(path, &block) {|static_file| ... }

Finds all occurrences of a given file path, within all static directories.

Parameters:

  • (String) path — The file path to search for.

Yields:

  • (static_file) — If a block is given, it will be passed every found path.

Yield Parameters:

  • (String) static_file — The path of a file within a static directory.

Returns:

  • (Array<String>) — The occurrences of the given file path within all static directories.


114
115
116
117
118
# File 'lib/static_paths/finders.rb', line 114

def each_static_file(path,&block)
  each_static_path(path) do |full_path|
    block.call(full_path) if File.file?(full_path)
  end
end

- (Object) each_static_path(path, &block) {|potential_path| ... }

Passes all existing static paths for the specified path, within the static directories, to the given block.

Parameters:

  • (String) path — The path to search for in all static directories.

Yields:

  • (potential_path) — The given block will be passed every existing combination of the given path and the static directories.

Yield Parameters:

  • (String) potential_path — An existing static path.


21
22
23
24
25
26
27
# File 'lib/static_paths/finders.rb', line 21

def each_static_path(path,&block)
  StaticPaths.paths.each do |dir|
    full_path = File.join(dir,path)

    block.call(full_path) if File.exists?(full_path)
  end
end

- (String?) find_static_dir(path)

Searches for a directory at the given path, within any static directory.

Parameters:

  • (String) path — The directory path to search for.

Returns:

  • (String, nil) — Returns the first valid directory at the given path within a static directory. Returns nil if the given path could not be found in any static directory.


75
76
77
78
79
80
81
# File 'lib/static_paths/finders.rb', line 75

def find_static_dir(path)
  each_static_path(path) do |full_path|
    return full_path if File.directory?(full_path)
  end

  return nil
end

- (String?) find_static_file(path)

Searches for a file at the given path, within any static directory.

Parameters:

  • (String) path — The file path to search for.

Returns:

  • (String, nil) — Returns the first valid file at the given path within a static directory. Returns nil if the given path could not be found in any static directory.


55
56
57
58
59
60
61
# File 'lib/static_paths/finders.rb', line 55

def find_static_file(path)
  each_static_path(path) do |full_path|
    return full_path if File.file?(full_path)
  end

  return nil
end

- (String?) find_static_path(path)

Searches for the given path within any static directory.

Parameters:

  • (String) path — The path to search for.

Returns:

  • (String, nil) — Returns the first valid match for the given path within a static directory. Returns nil if the given path could not be found in any static directory.


40
41
42
# File 'lib/static_paths/finders.rb', line 40

def find_static_path(path)
  Enumerator.new(self,:each_static_path,path).first
end

- (Array<String>) static_glob(pattern)

Finds all paths that match a given pattern, within all static directories.

Parameters:

  • (String) pattern — The path glob pattern to search with.

Returns:

  • (Array<String>) — The matching paths found within all static directories.


184
185
186
187
188
189
190
191
192
# File 'lib/static_paths/finders.rb', line 184

def static_glob(pattern)
  paths = []

  StaticPaths.paths.each do |path|
    paths += Dir[File.join(path,pattern)]
  end

  return paths
end