Module: Kamaze::Project::Tools::Packager::Filesystem::Operator::Utils
- Defined in:
- lib/kamaze/project/tools/packager/filesystem/operator/utils.rb
Overview
Utilities related to files/paths manipulations
Instance Method Summary collapse
-
#ls(dir) ⇒ Array<Pathname>
protected
List entries.
-
#map_dirs(paths) ⇒ Array<Pathname>
protected
Extract directories from given paths.
-
#purge(dir, options = {}) ⇒ Pathname
protected
Purge a directory.
-
#skel_dirs(basedir, entries, options = {}) ⇒ Pathname
protected
Make dirs from given basedir using entries (filepaths).
- #utils_methods ⇒ Array<Symbol> protected
Instance Method Details
#ls(dir) ⇒ Array<Pathname> (protected)
List entries
58 59 60 61 62 63 64 |
# File 'lib/kamaze/project/tools/packager/filesystem/operator/utils.rb', line 58 def ls(dir) # @formatter:off Pathname.new(dir).entries .map { |path| ::Pathname.new(path) } .delete_if { |path| ['.', '..'].include?(path.basename.to_s) } # @formatter:on end |
#map_dirs(paths) ⇒ Array<Pathname> (protected)
Extract directories from given paths
70 71 72 73 74 75 76 77 |
# File 'lib/kamaze/project/tools/packager/filesystem/operator/utils.rb', line 70 def map_dirs(paths) # @formatter:off paths.map { |path| ::Pathname.new(path) } .map(&:dirname) .delete_if { |path| ['.', '..'].include?(path.basename.to_s) } .uniq.sort # @formatter:on end |
#purge(dir, options = {}) ⇒ Pathname (protected)
Purge a directory
28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/kamaze/project/tools/packager/filesystem/operator/utils.rb', line 28 def purge(dir, = {}) = { verbose: true }.merge() dir = Pathname.new(dir) if dir.exist? ls(dir).each do |entry| rm_rf(dir.join(entry), **) end end dir end |
#skel_dirs(basedir, entries, options = {}) ⇒ Pathname (protected)
Make dirs from given basedir using entries (filepaths)
48 49 50 51 52 |
# File 'lib/kamaze/project/tools/packager/filesystem/operator/utils.rb', line 48 def skel_dirs(basedir, entries, = {}) Pathname.new(basedir).tap do map_dirs(entries).each { |dir| mkdir_p(basedir.join(dir), **) } end end |
#utils_methods ⇒ Array<Symbol> (protected)
80 81 82 |
# File 'lib/kamaze/project/tools/packager/filesystem/operator/utils.rb', line 80 def utils_methods FileUtils.public_methods - self.public_methods end |