Module: DataPaths::Finders
- Includes:
- Enumerable
- Defined in:
- lib/data_paths/finders.rb
Instance Method Summary collapse
-
#all_data_dirs(path) ⇒ Array<String>
Finds all occurrences of a given directory path, within all data directories.
-
#all_data_files(path) ⇒ Array<String>
Finds all occurrences of a given file path, within all data directories.
-
#all_data_paths(path) ⇒ Array<String>
Finds all occurrences of a given path, within all data directories.
-
#data_glob(pattern) ⇒ Array<String>
Finds all paths that match a given pattern, within all data directories.
-
#each_data_dir(path) {|data_dir| ... } ⇒ Array<String>
Finds all occurrences of a given directory path, within all data directories.
-
#each_data_file(path) {|data_file| ... } ⇒ Array<String>
Finds all occurrences of a given file path, within all data directories.
-
#each_data_path(path) {|potential_path| ... } ⇒ Object
Passes all existing data paths for the specified path, within the data directories, to the given block.
-
#find_data_dir(path) ⇒ String?
Searches for a directory at the given path, within any data directory.
-
#find_data_file(path) ⇒ String?
Searches for a file at the given path, within any data directory.
-
#find_data_path(path) ⇒ String?
Searches for the given path within any data directory.
Instance Method Details
#all_data_dirs(path) ⇒ Array<String>
Finds all occurrences of a given directory path, within all data directories.
171 172 173 |
# File 'lib/data_paths/finders.rb', line 171 def all_data_dirs(path) enum_for(:each_data_dir,path).to_a end |
#all_data_files(path) ⇒ Array<String>
Finds all occurrences of a given file path, within all data directories.
133 134 135 |
# File 'lib/data_paths/finders.rb', line 133 def all_data_files(path) enum_for(:each_data_file,path).to_a end |
#all_data_paths(path) ⇒ Array<String>
Finds all occurrences of a given path, within all data directories.
94 95 96 |
# File 'lib/data_paths/finders.rb', line 94 def all_data_paths(path) enum_for(:each_data_path,path).to_a end |
#data_glob(pattern) ⇒ Array<String>
Finds all paths that match a given pattern, within all data directories.
185 186 187 188 189 190 191 192 193 |
# File 'lib/data_paths/finders.rb', line 185 def data_glob(pattern) paths = [] DataPaths.paths.each do |path| paths += Dir[File.join(path,pattern)] end return paths end |
#each_data_dir(path) {|data_dir| ... } ⇒ Array<String>
Finds all occurrences of a given directory path, within all data directories.
154 155 156 157 158 |
# File 'lib/data_paths/finders.rb', line 154 def each_data_dir(path,&block) each_data_path(path) do |full_path| block.call(full_path) if File.directory?(full_path) end end |
#each_data_file(path) {|data_file| ... } ⇒ Array<String>
Finds all occurrences of a given file path, within all data directories.
115 116 117 118 119 |
# File 'lib/data_paths/finders.rb', line 115 def each_data_file(path,&block) each_data_path(path) do |full_path| block.call(full_path) if File.file?(full_path) end end |
#each_data_path(path) {|potential_path| ... } ⇒ Object
Passes all existing data paths for the specified path, within the data directories, to the given block.
23 24 25 26 27 28 29 |
# File 'lib/data_paths/finders.rb', line 23 def each_data_path(path,&block) DataPaths.paths.each do |dir| full_path = File.join(dir,path) block.call(full_path) if File.exists?(full_path) end end |
#find_data_dir(path) ⇒ String?
Searches for a directory at the given path, within any data directory.
77 78 79 80 81 82 83 |
# File 'lib/data_paths/finders.rb', line 77 def find_data_dir(path) each_data_path(path) do |full_path| return full_path if File.directory?(full_path) end return nil end |
#find_data_file(path) ⇒ String?
Searches for a file at the given path, within any data directory.
57 58 59 60 61 62 63 |
# File 'lib/data_paths/finders.rb', line 57 def find_data_file(path) each_data_path(path) do |full_path| return full_path if File.file?(full_path) end return nil end |
#find_data_path(path) ⇒ String?
Searches for the given path within any data directory.
42 43 44 |
# File 'lib/data_paths/finders.rb', line 42 def find_data_path(path) enum_for(:each_data_path,path).first end |