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.
232 233 234 235 236 237 238 |
# File 'lib/philiprehberger/tar.rb', line 232 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.
241 242 243 244 245 246 247 |
# File 'lib/philiprehberger/tar.rb', line 241 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.
250 251 252 253 254 |
# File 'lib/philiprehberger/tar.rb', line 250 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.
257 258 259 260 261 |
# File 'lib/philiprehberger/tar.rb', line 257 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 |