Class: Philiprehberger::Tar::FilteredWriter
- Inherits:
-
Object
- Object
- Philiprehberger::Tar::FilteredWriter
- Defined in:
- lib/philiprehberger/tar.rb
Overview
A wrapper around Writer that applies include/exclude/newer_than filters.
Instance Method Summary collapse
-
#add_file(path, name: nil, total: nil) ⇒ Object
Add a file from the filesystem, applying filters.
-
#add_string(name, content, mode: 0o644, total: nil) ⇒ Object
Add a file from a string, applying include/exclude filters.
-
#add_symlink(name, target:, total: nil) ⇒ Object
Add a symlink, applying include/exclude filters.
-
#initialize(writer, include: nil, exclude: nil, newer_than: nil, on_progress: nil) ⇒ FilteredWriter
constructor
A new instance of FilteredWriter.
Constructor Details
#initialize(writer, include: nil, exclude: nil, newer_than: nil, on_progress: nil) ⇒ FilteredWriter
Returns a new instance of FilteredWriter.
203 204 205 206 207 208 209 |
# File 'lib/philiprehberger/tar.rb', line 203 def initialize(writer, include: nil, exclude: nil, newer_than: nil, on_progress: nil) @writer = writer @include_patterns = include ? Array(include) : nil @exclude_patterns = exclude ? Array(exclude) : nil @newer_than = newer_than @on_progress = on_progress end |
Instance Method Details
#add_file(path, name: nil, total: nil) ⇒ Object
Add a file from the filesystem, applying filters.
212 213 214 215 216 217 218 |
# File 'lib/philiprehberger/tar.rb', line 212 def add_file(path, name: nil, total: nil) check_name = name || File.basename(path) return unless passes_filter?(check_name) return if @newer_than && File.mtime(path) <= @newer_than @writer.add_file(path, name: name, on_progress: @on_progress, total: total) end |
#add_string(name, content, mode: 0o644, total: nil) ⇒ Object
Add a file from a string, applying include/exclude filters.
221 222 223 224 225 |
# File 'lib/philiprehberger/tar.rb', line 221 def add_string(name, content, mode: 0o644, total: nil) return unless passes_filter?(name) @writer.add_string(name, content, mode: mode, on_progress: @on_progress, total: total) end |
#add_symlink(name, target:, total: nil) ⇒ Object
Add a symlink, applying include/exclude filters.
228 229 230 231 232 |
# File 'lib/philiprehberger/tar.rb', line 228 def add_symlink(name, target:, total: nil) return unless passes_filter?(name) @writer.add_symlink(name, target: target, on_progress: @on_progress, total: total) end |