Class: Cabriolet::FileManager
- Inherits:
-
Object
- Object
- Cabriolet::FileManager
- Includes:
- Enumerable
- Defined in:
- lib/cabriolet/file_manager.rb
Overview
Manages collection of files for archive creation
Single responsibility: File list management and enumeration. Provides unified interface for adding files from disk or memory, and supports standard Ruby enumeration patterns.
Instance Method Summary collapse
-
#[](index) ⇒ FileEntry?
Get entry by index.
-
#add_data(data, archive_path, **options) ⇒ FileEntry
Add file from memory.
-
#add_file(source_path, archive_path = nil, **options) ⇒ FileEntry
Add file from disk.
-
#all ⇒ Array<FileEntry>
Get all entries.
-
#clear ⇒ self
Clear all entries.
-
#disk_files ⇒ Array<FileEntry>
Get files from disk.
-
#each {|FileEntry| ... } ⇒ Object
Enumerate entries (Enumerable interface).
-
#empty? ⇒ Boolean
Check if empty.
-
#find_by_path(path) ⇒ FileEntry?
Find entry by archive path.
-
#initialize ⇒ FileManager
constructor
Initialize empty file manager.
-
#memory_files ⇒ Array<FileEntry>
Get files from memory.
-
#path_exists?(path) ⇒ Boolean
Check if archive path exists.
-
#size ⇒ Integer
(also: #count)
Get count of entries.
-
#total_size ⇒ Integer
Calculate total size of all files.
Constructor Details
#initialize ⇒ FileManager
Initialize empty file manager
21 22 23 |
# File 'lib/cabriolet/file_manager.rb', line 21 def initialize @entries = [] end |
Instance Method Details
#[](index) ⇒ FileEntry?
Get entry by index
88 89 90 |
# File 'lib/cabriolet/file_manager.rb', line 88 def [](index) @entries[index] end |
#add_data(data, archive_path, **options) ⇒ FileEntry
Add file from memory
51 52 53 54 55 56 57 58 59 60 |
# File 'lib/cabriolet/file_manager.rb', line 51 def add_data(data, archive_path, **) entry = FileEntry.new( data: data, archive_path: archive_path, **, ) @entries << entry entry end |
#add_file(source_path, archive_path = nil, **options) ⇒ FileEntry
Add file from disk
32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/cabriolet/file_manager.rb', line 32 def add_file(source_path, archive_path = nil, **) archive_path ||= File.basename(source_path) entry = FileEntry.new( source: source_path, archive_path: archive_path, **, ) @entries << entry entry end |
#all ⇒ Array<FileEntry>
Get all entries
95 96 97 |
# File 'lib/cabriolet/file_manager.rb', line 95 def all @entries.dup end |
#clear ⇒ self
Clear all entries
102 103 104 105 |
# File 'lib/cabriolet/file_manager.rb', line 102 def clear @entries.clear self end |
#disk_files ⇒ Array<FileEntry>
Get files from disk
117 118 119 |
# File 'lib/cabriolet/file_manager.rb', line 117 def disk_files @entries.select(&:from_disk?) end |
#each {|FileEntry| ... } ⇒ Object
Enumerate entries (Enumerable interface)
65 66 67 |
# File 'lib/cabriolet/file_manager.rb', line 65 def each(&) @entries.each(&) end |
#empty? ⇒ Boolean
Check if empty
72 73 74 |
# File 'lib/cabriolet/file_manager.rb', line 72 def empty? @entries.empty? end |
#find_by_path(path) ⇒ FileEntry?
Find entry by archive path
132 133 134 |
# File 'lib/cabriolet/file_manager.rb', line 132 def find_by_path(path) @entries.find { |entry| entry.archive_path == path } end |
#memory_files ⇒ Array<FileEntry>
Get files from memory
124 125 126 |
# File 'lib/cabriolet/file_manager.rb', line 124 def memory_files @entries.select(&:from_memory?) end |
#path_exists?(path) ⇒ Boolean
Check if archive path exists
140 141 142 |
# File 'lib/cabriolet/file_manager.rb', line 140 def path_exists?(path) !find_by_path(path).nil? end |
#size ⇒ Integer Also known as: count
Get count of entries
79 80 81 |
# File 'lib/cabriolet/file_manager.rb', line 79 def size @entries.size end |
#total_size ⇒ Integer
Calculate total size of all files
110 111 112 |
# File 'lib/cabriolet/file_manager.rb', line 110 def total_size @entries.sum(&:size) end |