Class: Kamaze::Project::Tools::Packager::Filesystem::Operator
- Includes:
- Utils
- Defined in:
- lib/kamaze/project/tools/packager/filesystem/operator.rb
Overview
Filesystem operator (manipulator)
This class is intended to manipulate a Filesystem
.
Defined Under Namespace
Modules: Utils
Instance Attribute Summary collapse
- #fs ⇒ Kamaze::Project::Tools::Packager::Filesystem readonly
- #options ⇒ Hash{Symbol => Object} readonly protected
Instance Method Summary collapse
-
#initialize(filesystem, options = {}) ⇒ Operator
constructor
A new instance of Operator.
-
#ls(dir) ⇒ Array<Pathname>
included
from Utils
protected
List entries.
-
#map_dirs(paths) ⇒ Array<Pathname>
included
from Utils
protected
Extract directories from given paths.
-
#prepare ⇒ self
Prepare package.
-
#prepare_srcdir ⇒ self
Prepare
src
dir. -
#purge(dir, options = {}) ⇒ Pathname
included
from Utils
protected
Purge a directory.
-
#purge_purgeables ⇒ self
Purge purgeables elements.
-
#skel_dirs(basedir, entries, options = {}) ⇒ Pathname
included
from Utils
protected
Make dirs from given basedir using entries (filepaths).
- #utils_methods ⇒ Array<Symbol> included from Utils protected
- #verbose? ⇒ Boolean
Constructor Details
#initialize(filesystem, options = {}) ⇒ Operator
Returns a new instance of Operator.
31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/kamaze/project/tools/packager/filesystem/operator.rb', line 31 def initialize(filesystem, = {}) @fs = filesystem @options = { verbose: true }.merge(.to_h) # Pass included methods to protected utils_methods.each do |m| next unless self.public_methods.include?(m) # rubocop:disable Style/AccessModifierDeclarations self.singleton_class.class_eval { protected m } # rubocop:enable Style/AccessModifierDeclarations end end |
Instance Attribute Details
#fs ⇒ Kamaze::Project::Tools::Packager::Filesystem (readonly)
26 27 28 |
# File 'lib/kamaze/project/tools/packager/filesystem/operator.rb', line 26 def fs @fs end |
#options ⇒ Hash{Symbol => Object} (readonly, protected)
90 91 92 |
# File 'lib/kamaze/project/tools/packager/filesystem/operator.rb', line 90 def @options end |
Instance Method Details
#ls(dir) ⇒ Array<Pathname> (protected) Originally defined in module Utils
List entries
#map_dirs(paths) ⇒ Array<Pathname> (protected) Originally defined in module Utils
Extract directories from given paths
#prepare ⇒ self
Prepare package
48 49 50 51 52 |
# File 'lib/kamaze/project/tools/packager/filesystem/operator.rb', line 48 def prepare fs.package_dirs.each_value { |dir| mkdir_p(dir, **) } self.purge_purgeables.prepare_srcdir end |
#prepare_srcdir ⇒ self
Prepare src
dir
Source files are refreshed (deleted and copied again)
68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/kamaze/project/tools/packager/filesystem/operator.rb', line 68 def prepare_srcdir src_dir = Pathname.new(fs.package_dirs.fetch(:src)) purge(src_dir, ) skel_dirs(src_dir, fs.source_files, ) fs.source_files.map do |path| origin = path.realpath # resolves symlinks cp(origin, src_dir.join(path), **.merge(preserve: true)) end self end |
#purge(dir, options = {}) ⇒ Pathname (protected) Originally defined in module Utils
Purge a directory
#purge_purgeables ⇒ self
Purge purgeables elements
57 58 59 60 61 |
# File 'lib/kamaze/project/tools/packager/filesystem/operator.rb', line 57 def purge_purgeables fs.purgeable_dirs.each_value { |dir| purge(dir, **) } self end |
#skel_dirs(basedir, entries, options = {}) ⇒ Pathname (protected) Originally defined in module Utils
Make dirs from given basedir using entries (filepaths)
#utils_methods ⇒ Array<Symbol> (protected) Originally defined in module Utils
#verbose? ⇒ Boolean
83 84 85 |
# File 'lib/kamaze/project/tools/packager/filesystem/operator.rb', line 83 def verbose? [:verbose] == true end |