Module: DataPaths::Finders
- 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) ⇒ Object
deprecated
Deprecated.
Will be removed in 1.0.0, please use #glob_data_paths instead.
-
#each_data_dir(path) {|data_dir| ... } ⇒ Enumerator
Finds all occurrences of a given directory path, within all data directories.
-
#each_data_file(path) {|data_file| ... } ⇒ Enumerator
Finds all occurrences of a given file path, within all data directories.
-
#each_data_path(path) {|potential_path| ... } ⇒ Enumerator
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.
-
#glob_data_paths(pattern) {|path| ... } ⇒ Array<String>
Finds all paths that match a given pattern, within all data directories.
-
#load_yaml_file(path) ⇒ Object
Loads the YAML file at the given path, within any data directory.
-
#load_yaml_files(path) ⇒ Array
Finds all occurrences of a given file path, within all data directories.
Instance Method Details
#all_data_dirs(path) ⇒ Array<String>
Finds all occurrences of a given directory path, within all data directories.
201 202 203 |
# File 'lib/data_paths/finders.rb', line 201 def all_data_dirs(path) 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.
162 163 164 |
# File 'lib/data_paths/finders.rb', line 162 def all_data_files(path) each_data_file(path).to_a end |
#all_data_paths(path) ⇒ Array<String>
Finds all occurrences of a given path, within all data directories.
106 107 108 |
# File 'lib/data_paths/finders.rb', line 106 def all_data_paths(path) each_data_path(path).to_a end |
#data_glob(pattern) ⇒ Object
Will be removed in 1.0.0, please use #glob_data_paths instead.
236 237 238 239 240 |
# File 'lib/data_paths/finders.rb', line 236 def data_glob(pattern) STDERR.puts "DEPRECATED: please use glob_data_paths instead." glob_data_paths(pattern) end |
#each_data_dir(path) {|data_dir| ... } ⇒ Enumerator
Finds all occurrences of a given directory path, within all data directories.
182 183 184 185 186 187 188 |
# File 'lib/data_paths/finders.rb', line 182 def each_data_dir(path) return enum_for(:each_data_dir,path) unless block_given? each_data_path(path) do |full_path| yield(full_path) if File.directory?(full_path) end end |
#each_data_file(path) {|data_file| ... } ⇒ Enumerator
Finds all occurrences of a given file path, within all data directories.
126 127 128 129 130 131 132 |
# File 'lib/data_paths/finders.rb', line 126 def each_data_file(path) return enum_for(:each_data_file,path) unless block_given? each_data_path(path) do |full_path| yield(full_path) if File.file?(full_path) end end |
#each_data_path(path) {|potential_path| ... } ⇒ Enumerator
Passes all existing data paths for the specified path, within the data directories, to the given block.
24 25 26 27 28 29 30 31 32 |
# File 'lib/data_paths/finders.rb', line 24 def each_data_path(path) return enum_for(:each_data_path,path) unless block_given? DataPaths.paths.each do |dir| full_path = File.join(dir,path) yield(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.
93 94 95 |
# File 'lib/data_paths/finders.rb', line 93 def find_data_dir(path) each_data_path(path).find { |full_path| File.directory?(full_path) } end |
#find_data_file(path) ⇒ String?
Searches for a file at the given path, within any data directory.
60 61 62 |
# File 'lib/data_paths/finders.rb', line 60 def find_data_file(path) each_data_path(path).find { |full_path| File.file?(full_path) } end |
#find_data_path(path) ⇒ String?
Searches for the given path within any data directory.
45 46 47 |
# File 'lib/data_paths/finders.rb', line 45 def find_data_path(path) each_data_path(path).first end |
#glob_data_paths(pattern) {|path| ... } ⇒ Array<String>
Finds all paths that match a given pattern, within all data directories.
224 225 226 227 228 229 230 |
# File 'lib/data_paths/finders.rb', line 224 def glob_data_paths(pattern,&block) return enum_for(:glob_data_paths,pattern).to_a unless block_given? DataPaths.paths.each do |path| Dir.glob(File.join(path,pattern),&block) end end |
#load_yaml_file(path) ⇒ Object
Loads the YAML file at the given path, within any data directory.
75 76 77 78 79 |
# File 'lib/data_paths/finders.rb', line 75 def load_yaml_file(path) if (file = find_data_file(path)) YAML.load_file(file) end end |
#load_yaml_files(path) ⇒ Array
Finds all occurrences of a given file path, within all data directories.
146 147 148 |
# File 'lib/data_paths/finders.rb', line 146 def load_yaml_files(path) each_data_file(path).map { |file| YAML.load_file(file) } end |