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

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

Overview

Utilities related to files/paths manipulations

Instance Method Summary collapse

Instance Method Details

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

List entries

Parameters:

  • dir (String)

Returns:

  • (Array<Pathname>)


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

Parameters:

  • paths (Array<String>)

Returns:

  • (Array<Pathname>)


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

Parameters:

  • dir (Pathname)

Returns:

  • (Pathname)


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, 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)

Parameters:

  • basedir (String|Pathname)
  • entries (Array<>)
  • options (Hash) (defaults to: {})

Returns:

  • (Pathname)


48
49
50
51
52
# File 'lib/kamaze/project/tools/packager/filesystem/operator/utils.rb', line 48

def skel_dirs(basedir, entries, options = {})
  Pathname.new(basedir).tap do
    map_dirs(entries).each { |dir| mkdir_p(basedir.join(dir), **options) }
  end
end

#utils_methodsArray<Symbol> (protected)

Returns:

  • (Array<Symbol>)


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