Class: Kamaze::Project::Tools::Packager::Filesystem::Operator

Inherits:
Object
  • Object
show all
Includes:
Utils
Defined in:
lib/kamaze/project/tools/packager/filesystem/operator.rb,
lib/kamaze/project/tools/packager.rb

Overview

Filesystem operator (manipulator)

This class is intended to manipulate a Filesystem.

Defined Under Namespace

Modules: Utils

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filesystem, options = {}) ⇒ Operator

Returns a new instance of Operator.

Parameters:

See Also:



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

def initialize(filesystem, options = {})
  @fs = filesystem
  @options = { verbose: true }.merge(options.to_h)

  # Pass included methods to protected
  utils_methods.each do |m|
    if self.public_methods.include?(m)
      self.singleton_class.class_eval { protected m }
    end
  end
end

Instance Attribute Details

#fsKamaze::Project::Tools::Packager::Filesystem (readonly)



20
21
22
# File 'lib/kamaze/project/tools/packager/filesystem/operator.rb', line 20

def fs
  @fs
end

#optionsHash (readonly, protected)

Returns:

  • (Hash)


82
83
84
# File 'lib/kamaze/project/tools/packager/filesystem/operator.rb', line 82

def options
  @options
end

Instance Method Details

#ls(dir) ⇒ Array<Pathname> (protected) Originally defined in module Utils

List entries

Parameters:

  • dir (String)

Returns:

  • (Array<Pathname>)

#map_dirs(paths) ⇒ Array<Pathname> (protected) Originally defined in module Utils

Extract directories from given paths

Parameters:

  • paths (Array<String>)

Returns:

  • (Array<Pathname>)

#prepareself

Prepare package

Returns:

  • (self)


40
41
42
43
44
# File 'lib/kamaze/project/tools/packager/filesystem/operator.rb', line 40

def prepare
  fs.package_dirs.each_value { |dir| mkdir_p(dir, options) }

  self.purge_purgeables.prepare_srcdir
end

#prepare_srcdirself

Prepare src dir

Source files are refreshed (deleted and copied again)

Returns:

  • (self)


60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/kamaze/project/tools/packager/filesystem/operator.rb', line 60

def prepare_srcdir
  src_dir = ::Pathname.new(fs.package_dirs.fetch(:src))

  purge(src_dir, options)
  skel_dirs(src_dir, fs.source_files, options)

  fs.source_files.map do |path|
    origin = path.realpath # resolves symlinks

    cp(origin, src_dir.join(path), options.merge(preserve: true))
  end

  self
end

#purge(dir, options = {}) ⇒ Pathname (protected) Originally defined in module Utils

Purge a directory

Parameters:

  • dir (Pathname)

Returns:

  • (Pathname)

#purge_purgeablesself

Purge purgeables elements

Returns:

  • (self)


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

def purge_purgeables
  fs.purgeable_dirs.each_value { |dir| purge(dir, options) }

  self
end

#skel_dirs(basedir, entries, options = {}) ⇒ Pathname (protected) Originally defined in module Utils

Make dirs from given basedir using entries (filepaths)

Parameters:

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

Returns:

  • (Pathname)

#utils_methodsArray<Symbol> (protected) Originally defined in module Utils

Returns:

  • (Array<Symbol>)

#verbose?Boolean

Returns:

  • (Boolean)


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

def verbose?
  options[:verbose] == true
end