Class: Fontist::ValidationCache
- Inherits:
-
Lutaml::Model::Serializable
- Object
- Lutaml::Model::Serializable
- Fontist::ValidationCache
- Defined in:
- lib/fontist/validation.rb
Overview
Validation cache for storing/reusing validation results. Uses file metadata for automatic cache invalidation. Persisted to disk for fast subsequent validation runs.
Instance Method Summary collapse
-
#get(path) ⇒ Object
Get validation result for a path, checking if file has changed.
-
#set(result) ⇒ Object
Add or update a validation result.
-
#stale? ⇒ Boolean
Check if cache is stale (older than 24 hours).
-
#to_lookup ⇒ Object
Build lookup hash for fast O(1) access by path (non-shared state).
Instance Method Details
#get(path) ⇒ Object
Get validation result for a path, checking if file has changed
100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/fontist/validation.rb', line 100 def get(path) return nil unless File.exist?(path) stat = File.stat(path) entries.find do |entry| next unless entry.path == path # Check if file has changed since caching entry.file_size == stat.size && entry.file_mtime == stat.mtime.to_i end end |
#set(result) ⇒ Object
Add or update a validation result
114 115 116 117 118 119 120 |
# File 'lib/fontist/validation.rb', line 114 def set(result) # Remove existing entry for same path @entries = entries.reject { |e| e.path == result.path } @entries << result @generated_at = Time.now.to_i self end |
#stale? ⇒ Boolean
Check if cache is stale (older than 24 hours)
123 124 125 126 127 |
# File 'lib/fontist/validation.rb', line 123 def stale? return true if @generated_at.nil? (Time.now.to_i - @generated_at) > (24 * 60 * 60) end |
#to_lookup ⇒ Object
Build lookup hash for fast O(1) access by path (non-shared state)
95 96 97 |
# File 'lib/fontist/validation.rb', line 95 def to_lookup entries.index_by(&:path) end |