Class: Omnizip::Formats::SevenZip::FileCollector

Inherits:
Object
  • Object
show all
Defined in:
lib/omnizip/formats/seven_zip/file_collector.rb

Overview

Collects files and directories for archiving Handles file metadata, timestamps, and attributes

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeFileCollector

Initialize collector



14
15
16
17
# File 'lib/omnizip/formats/seven_zip/file_collector.rb', line 14

def initialize
  @entries = []
  @base_path = nil
end

Instance Attribute Details

#entriesObject (readonly)

Returns the value of attribute entries.



11
12
13
# File 'lib/omnizip/formats/seven_zip/file_collector.rb', line 11

def entries
  @entries
end

Instance Method Details

#add_glob(pattern, base_path: nil) ⇒ Object

Add files matching glob pattern

Parameters:

  • pattern (String)

    Glob pattern

  • base_path (String, nil) (defaults to: nil)

    Base path for relative names



41
42
43
44
45
46
47
# File 'lib/omnizip/formats/seven_zip/file_collector.rb', line 41

def add_glob(pattern, base_path: nil)
  @base_path ||= base_path || Dir.pwd

  Dir.glob(pattern).each do |path|
    add_path(path)
  end
end

#add_path(path, archive_path: nil, recursive: true) ⇒ Object

Add path (file or directory) to collection

Parameters:

  • path (String)

    Path to file or directory

  • archive_path (String, nil) (defaults to: nil)

    Path in archive (nil = auto)

  • recursive (Boolean) (defaults to: true)

    Recursively add directories



24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/omnizip/formats/seven_zip/file_collector.rb', line 24

def add_path(path, archive_path: nil, recursive: true)
  path = File.expand_path(path)
  raise "Path not found: #{path}" unless File.exist?(path)

  @base_path ||= File.dirname(path)

  if File.directory?(path)
    add_directory(path, archive_path, recursive)
  else
    add_file(path, archive_path)
  end
end

#collect_filesArray<Models::FileEntry>

Get collected file entries

Returns:



52
53
54
# File 'lib/omnizip/formats/seven_zip/file_collector.rb', line 52

def collect_files
  @entries.sort_by(&:name)
end