Module: Kamaze::Project::Tools::Packager::Filesystem::Operator::Utils

Includes:
FileUtils
Included in:
Kamaze::Project::Tools::Packager::Filesystem::Operator
Defined in:
lib/kamaze/project/tools/packager/filesystem/operator/utils.rb,
lib/kamaze/project/tools/packager.rb

Overview

Utilities related to files/paths manipulations

Instance Method Summary collapse

Instance Method Details

#ls(dir) ⇒ Array<Pathname> (protected)

List entries



56
57
58
59
60
# File 'lib/kamaze/project/tools/packager/filesystem/operator/utils.rb', line 56

def ls(dir)
  ::Pathname.new(dir).entries
            .map { |path| ::Pathname.new(path) }
            .delete_if { |path| ['.', '..'].include?(path.basename.to_s) }
end

#map_dirs(paths) ⇒ Array<Pathname> (protected)

Extract directories from given paths



66
67
68
69
70
71
# File 'lib/kamaze/project/tools/packager/filesystem/operator/utils.rb', line 66

def map_dirs(paths)
  paths.map { |path| ::Pathname.new(path) }
       .map(&:dirname)
       .delete_if { |path| ['.', '..'].include?(path.basename.to_s) }
       .uniq.sort
end

#purge(dir, options = {}) ⇒ Pathname (protected)

Purge a directory



25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/kamaze/project/tools/packager/filesystem/operator/utils.rb', line 25

def purge(dir, options = {})
  options = { verbose: true }.merge(options)
  dir = ::Pathname.new(dir)

  if dir.exist?
    ls(dir).each do |entry|
      rm_rf(dir.join(entry), options)
    end
  end

  dir
end

#skel_dirs(basedir, entries, options = {}) ⇒ Pathname (protected)

Make dirs from given basedir using entries (filepaths)



44
45
46
47
48
49
50
# File 'lib/kamaze/project/tools/packager/filesystem/operator/utils.rb', line 44

def skel_dirs(basedir, entries, options = {})
  basedir = ::Pathname.new(basedir)

  map_dirs(entries).each { |dir| mkdir_p(basedir.join(dir), options) }

  basedir
end

#utils_methodsArray<Symbol> (protected)



74
75
76
# File 'lib/kamaze/project/tools/packager/filesystem/operator/utils.rb', line 74

def utils_methods
  FileUtils.public_methods - self.public_methods
end