class Fontist::Indexes::DirectorySnapshot
Value object representing the state of a directory at a point in time Immutable - returns new instances for state changes
Attributes
Public Class Methods
Source
# File lib/fontist/indexes/directory_snapshot.rb, line 12 def self.create(directory_path) directory_path = directory_path.to_s files = IncrementalScanner.scan_directory(directory_path) new(directory_path, files, Time.now.to_i) end
Create a new snapshot by scanning a directory Returns: DirectorySnapshot instance
Source
# File lib/fontist/indexes/directory_snapshot.rb, line 19 def self.from_hash(hash) new( hash[:directory_path].to_s, hash[:files], hash[:scanned_at], ) end
Create from existing data (for cache restoration)
Source
# File lib/fontist/indexes/directory_snapshot.rb, line 59 def initialize(directory_path, files, scanned_at) @directory_path = directory_path @files = files.freeze # Immutable @files_by_filename = files.each_with_object({}) do |f, h| h[f[:filename]] = f end.freeze @scanned_at = scanned_at end
Public Instance Methods
Source
# File lib/fontist/indexes/directory_snapshot.rb, line 44 def file_count @files.length end
Get count of files in snapshot
Source
# File lib/fontist/indexes/directory_snapshot.rb, line 29 def file_info(filename) @files_by_filename[filename] end
Get file info for a specific filename Returns: Hash with file metadata or nil if not found
Source
# File lib/fontist/indexes/directory_snapshot.rb, line 39 def has_file?(filename) @files_by_filename.key?(filename) end
Check if file exists in snapshot
Source
# File lib/fontist/indexes/directory_snapshot.rb, line 34 def older_than?(seconds) Time.now.to_i - @scanned_at > seconds end
Check if snapshot is older than given seconds
Source
# File lib/fontist/indexes/directory_snapshot.rb, line 49 def to_h { directory_path: @directory_path, files: @files, scanned_at: @scanned_at, } end
Convert to hash for serialization