Module: Melai::DirHelpers
- Defined in:
- lib/melai/dir_helpers.rb
Overview
This module provides some helper methods, specificlally pertaining to directory creation, removal, searching, et al.
Instance Method Summary collapse
-
#ensure_directory(directory) ⇒ Bool
Ensure a directory exists.
-
#ensure_symlink(symlink_name, original_file) ⇒ Bool
Ensure a symlink exists.
-
#find_packages(packages_path) ⇒ Array
Get any files with a known package extension.
Instance Method Details
#ensure_directory(directory) ⇒ Bool
Ensure a directory exists
20 21 22 23 24 25 26 |
# File 'lib/melai/dir_helpers.rb', line 20 def ensure_directory(directory) unless File.directory?(directory) FileUtils.mkdir_p(directory) return true end return false end |
#ensure_symlink(symlink_name, original_file) ⇒ Bool
Ensure a symlink exists
33 34 35 36 37 38 39 40 41 |
# File 'lib/melai/dir_helpers.rb', line 33 def ensure_symlink(symlink_name, original_file) unless File.symlink?(symlink_name) ensure_directory(File.dirname(symlink_name)) target = File.absolute_path(original_file) File.symlink(target, symlink_name) return true end return false end |
#find_packages(packages_path) ⇒ Array
Get any files with a known package extension
11 12 13 14 |
# File 'lib/melai/dir_helpers.rb', line 11 def find_packages(packages_path) packages = File.join(packages_path, "**", "*.{rpm,deb}") return Dir.glob(packages).sort() end |