class Fontist::Indexes::DirectoryChange
Value object representing a single change detected in a directory Immutable - describes what changed between two snapshots
Constants
- ADDED
-
Change types
- MODIFIED
- REMOVED
- UNCHANGED
Attributes
Public Class Methods
Source
# File lib/fontist/indexes/directory_change.rb, line 17 def added(filename, new_info) new(ADDED, filename, nil, new_info) end
Create an added file change
Source
# File lib/fontist/indexes/directory_change.rb, line 38 def diff(old_snapshot, new_snapshot) changes = [] # Check for added and modified files new_snapshot.files.each do |new_file| filename = new_file[:filename] old_file = old_snapshot.file_info(filename) if old_file.nil? changes << added(filename, new_file) elsif file_modified?(old_file, new_file) changes << modified(filename, old_file, new_file) end end # Check for removed files old_snapshot.files.each do |old_file| filename = old_file[:filename] unless new_snapshot.has_file?(filename) changes << removed(filename, old_file) end end changes end
Compare two snapshots and detect changes Returns: Array of DirectoryChange objects
Source
# File lib/fontist/indexes/directory_change.rb, line 22 def modified(filename, old_info, new_info) new(MODIFIED, filename, old_info, new_info) end
Create a modified file change
Source
# File lib/fontist/indexes/directory_change.rb, line 76 def initialize(change_type, filename, old_info, new_info) @change_type = change_type @filename = filename @old_info = old_info @new_info = new_info freeze # Immutable end
Instance methods
Source
# File lib/fontist/indexes/directory_change.rb, line 27 def removed(filename, old_info) new(REMOVED, filename, old_info, nil) end
Create a removed file change
Source
# File lib/fontist/indexes/directory_change.rb, line 32 def unchanged(filename, info) new(UNCHANGED, filename, info, info) end
Create an unchanged file change
Public Instance Methods
Source
# File lib/fontist/indexes/directory_change.rb, line 85 def added? @change_type == ADDED end
Query methods for change type
Source
# File lib/fontist/indexes/directory_change.rb, line 89 def modified? @change_type == MODIFIED end
Source
# File lib/fontist/indexes/directory_change.rb, line 93 def removed? @change_type == REMOVED end
Source
# File lib/fontist/indexes/directory_change.rb, line 102 def to_h { change_type: @change_type, filename: @filename, old_info: @old_info, new_info: @new_info, } end
Convert to hash for serialization
Source
# File lib/fontist/indexes/directory_change.rb, line 97 def unchanged? @change_type == UNCHANGED end