Module: Rays::Utils::FileUtils
- Defined in:
- lib/rays/utils/file_utils.rb
Defined Under Namespace
Classes: PropertiesFile, YamlFile
Class Method Summary collapse
-
.find_directories(path, hidden = false) ⇒ Object
Get list of child directory names of a given directory.
-
.find_down(dir, file) ⇒ Object
Find a file specified by regexp in a given directory recursively down.
-
.find_up(file, dir = Dir.pwd, limit = '/') ⇒ Object
Find a parent directory which contains a given file name (no patterns allowed).
-
.parent(dir) ⇒ Object
Get parent path from a given path.
Class Method Details
.find_directories(path, hidden = false) ⇒ Object
Get list of child directory names of a given directory. Goes one level down only.
62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/rays/utils/file_utils.rb', line 62 def self.find_directories path, hidden=false dirs = [] Dir.glob("#{path}/*/").each do |dir| dirs << File.basename(dir) end if hidden Dir.glob("#{path}/.*/").each do |dir| basename = File.basename(dir) dirs << File.basename(dir) if basename != '.' and basename != '..' end end dirs end |
.find_down(dir, file) ⇒ Object
Find a file specified by regexp in a given directory recursively down.
38 39 40 41 42 43 44 45 46 47 |
# File 'lib/rays/utils/file_utils.rb', line 38 def self.find_down dir, file files = [] if Dir.exist?(dir) Find.find(dir) do |file_path| next unless file_path.match(file) files << file_path end end files end |
.find_up(file, dir = Dir.pwd, limit = '/') ⇒ Object
Find a parent directory which contains a given file name (no patterns allowed)
52 53 54 55 56 |
# File 'lib/rays/utils/file_utils.rb', line 52 def self.find_up file, dir = Dir.pwd, limit = '/' return nil if dir.eql? limit or !dir.start_with?(limit) return dir unless Dir.new(dir).find_index(file).nil? find_up file, Pathname.new(dir).parent.to_s, limit end |
.parent(dir) ⇒ Object
Get parent path from a given path
30 31 32 33 |
# File 'lib/rays/utils/file_utils.rb', line 30 def self.parent dir return nil unless Dir.exists?(dir) Pathname.new(dir).parent.to_s end |