Module: MyCore::Dir::ClassMethods
- Defined in:
- lib/my_core/dir.rb
Instance Method Summary collapse
-
#dir_children(dirname = mpwd) ⇒ Object
Returns entries from simple_entries() that are directories.
-
#file_children(dirname = mpwd) ⇒ Object
Returns entries from simple_entries() that are files.
-
#full_entries(dirname = mpwd) ⇒ Object
Returns the full paths of simple_entries().
-
#get_level_children(dirname, level) ⇒ Object
used recursively by levels_of_children.
-
#levels_of_children(dirname = mpwd, max_level = 1000) ⇒ Object
Returns all simple_entries under a directory for the specified depth.
-
#mpwd ⇒ Object
Returns current directory with a ‘/’ appended.
-
#nonlink_entries(dirname = mpwd) ⇒ Object
Returns entries from simple_entries() that are not symlinks.
-
#simple_entries(dirname = mpwd) ⇒ Object
Returns everything in a directory that entries() would except for ‘.’, ‘..’ and vim’s backup files ie files ending with ~ or .sw*.
Instance Method Details
#dir_children(dirname = mpwd) ⇒ Object
Returns entries from simple_entries() that are directories.
11 12 13 14 15 |
# File 'lib/my_core/dir.rb', line 11 def dir_children(dirname=mpwd) simple_entries(dirname).find_all {|e| File.directory?(File.join(dirname, e)) } end |
#file_children(dirname = mpwd) ⇒ Object
Returns entries from simple_entries() that are files.
18 19 20 21 22 |
# File 'lib/my_core/dir.rb', line 18 def file_children(dirname=mpwd) simple_entries(dirname).find_all {|e| File.file?(File.join(dirname,e)) } end |
#full_entries(dirname = mpwd) ⇒ Object
Returns the full paths of simple_entries().
40 41 42 |
# File 'lib/my_core/dir.rb', line 40 def full_entries(dirname=mpwd) simple_entries(dirname).map {|e| File.join(dirname,e) } end |
#get_level_children(dirname, level) ⇒ Object
used recursively by levels_of_children
54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/my_core/dir.rb', line 54 def get_level_children(dirname,level) #:nodoc: dir_children = full_entries(dirname) @level_children += dir_children if level < @max_level dir_children.each {|e| if File.directory?(e) get_level_children(e,level + 1) end } end end |
#levels_of_children(dirname = mpwd, max_level = 1000) ⇒ Object
Returns all simple_entries under a directory for the specified depth. If no depth specified it’ll return all entries under the directory.
46 47 48 49 50 51 |
# File 'lib/my_core/dir.rb', line 46 def levels_of_children(dirname=mpwd,max_level=1000) @max_level = max_level @level_children = [] get_level_children(dirname,0) @level_children end |
#mpwd ⇒ Object
Returns current directory with a ‘/’ appended.
6 7 8 |
# File 'lib/my_core/dir.rb', line 6 def mpwd ::Dir.pwd + "/" end |
#nonlink_entries(dirname = mpwd) ⇒ Object
Returns entries from simple_entries() that are not symlinks.
33 34 35 36 37 |
# File 'lib/my_core/dir.rb', line 33 def nonlink_entries(dirname=mpwd) simple_entries(dirname).select {|e| ! File.symlink?(File.join(dirname,e)) } end |
#simple_entries(dirname = mpwd) ⇒ Object
Returns everything in a directory that entries() would except for ‘.’, ‘..’ and vim’s backup files ie files ending with ~ or .sw*. You should override this method to take advantage of methods based on it.
27 28 29 30 |
# File 'lib/my_core/dir.rb', line 27 def simple_entries(dirname=mpwd) dir_files = ::Dir.entries(dirname) files = dir_files - ['.','..'] - dir_files.grep(/~$/) - dir_files.grep(/\.sw[o-z]$/) end |