Class: Fontist::Indexes::DirectorySnapshot
- Inherits:
-
Object
- Object
- Fontist::Indexes::DirectorySnapshot
- Defined in:
- lib/fontist/indexes/directory_snapshot.rb
Overview
Value object representing the state of a directory at a point in time Immutable - returns new instances for state changes
Instance Attribute Summary collapse
-
#directory_path ⇒ Object
readonly
Returns the value of attribute directory_path.
-
#files ⇒ Object
readonly
Returns the value of attribute files.
-
#scanned_at ⇒ Object
readonly
Returns the value of attribute scanned_at.
Class Method Summary collapse
-
.create(directory_path) ⇒ Object
Create a new snapshot by scanning a directory Returns: DirectorySnapshot instance.
-
.from_hash(hash) ⇒ Object
Create from existing data (for cache restoration).
Instance Method Summary collapse
-
#file_count ⇒ Object
Get count of files in snapshot.
-
#file_info(filename) ⇒ Object
Get file info for a specific filename Returns: Hash with file metadata or nil if not found.
-
#has_file?(filename) ⇒ Boolean
Check if file exists in snapshot.
-
#older_than?(seconds) ⇒ Boolean
Check if snapshot is older than given seconds.
-
#to_h ⇒ Object
Convert to hash for serialization.
Instance Attribute Details
#directory_path ⇒ Object (readonly)
Returns the value of attribute directory_path.
6 7 8 |
# File 'lib/fontist/indexes/directory_snapshot.rb', line 6 def directory_path @directory_path end |
#files ⇒ Object (readonly)
Returns the value of attribute files.
6 7 8 |
# File 'lib/fontist/indexes/directory_snapshot.rb', line 6 def files @files end |
#scanned_at ⇒ Object (readonly)
Returns the value of attribute scanned_at.
6 7 8 |
# File 'lib/fontist/indexes/directory_snapshot.rb', line 6 def scanned_at @scanned_at end |
Class Method Details
.create(directory_path) ⇒ Object
Create a new snapshot by scanning a directory Returns: DirectorySnapshot instance
10 11 12 13 14 |
# File 'lib/fontist/indexes/directory_snapshot.rb', line 10 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 |
.from_hash(hash) ⇒ Object
Create from existing data (for cache restoration)
17 18 19 20 21 22 23 |
# File 'lib/fontist/indexes/directory_snapshot.rb', line 17 def self.from_hash(hash) new( hash[:directory_path].to_s, hash[:files], hash[:scanned_at], ) end |
Instance Method Details
#file_count ⇒ Object
Get count of files in snapshot
42 43 44 |
# File 'lib/fontist/indexes/directory_snapshot.rb', line 42 def file_count @files.length end |
#file_info(filename) ⇒ Object
Get file info for a specific filename Returns: Hash with file metadata or nil if not found
27 28 29 |
# File 'lib/fontist/indexes/directory_snapshot.rb', line 27 def file_info(filename) @files_by_filename[filename] end |
#has_file?(filename) ⇒ Boolean
Check if file exists in snapshot
37 38 39 |
# File 'lib/fontist/indexes/directory_snapshot.rb', line 37 def has_file?(filename) @files_by_filename.key?(filename) end |
#older_than?(seconds) ⇒ Boolean
Check if snapshot is older than given seconds
32 33 34 |
# File 'lib/fontist/indexes/directory_snapshot.rb', line 32 def older_than?(seconds) Time.now.to_i - @scanned_at > seconds end |
#to_h ⇒ Object
Convert to hash for serialization
47 48 49 50 51 52 53 |
# File 'lib/fontist/indexes/directory_snapshot.rb', line 47 def to_h { directory_path: @directory_path, files: @files, scanned_at: @scanned_at, } end |