class Fontist::SystemIndexFontCollection
Constants
- ALLOWED_KEYS
Attributes
Public Class Methods
Source
# File lib/fontist/system_index.rb, line 46 def self.from_file(path:, paths_loader:) # If the file does not exist, return a new collection return new.set_content(path, paths_loader) unless File.exist?(path) from_yaml(File.read(path)).set_content(path, paths_loader) end
Public Instance Methods
Source
# File lib/fontist/system_index.rb, line 108 def build(forced: false) previous_index = load_index updated_fonts = update if forced || changed?(updated_fonts, previous_index.fonts || []) to_file(@path) end self end
Source
# File lib/fontist/system_index.rb, line 63 def check_index Fontist.formulas_repo_path_exists! Array(fonts).each do |font| missing_keys = ALLOWED_KEYS.reject do |key| font.send(key) end raise_font_index_corrupted(font, missing_keys) if missing_keys.any? end end
Check if the content has all required keys
Source
# File lib/fontist/system_index.rb, line 80 def find(font, style) found_fonts = index.select do |file| file.family_name.casecmp?(font) && (style.nil? || file.type.casecmp?(style)) end found_fonts.empty? ? nil : found_fonts end
Source
# File lib/fontist/system_index.rb, line 89 def index return fonts unless index_changed? build check_index fonts end
Source
# File lib/fontist/system_index.rb, line 98 def index_changed? fonts.nil? || fonts.empty? || font_paths != (@paths_loader&.call || []).sort.uniq end
Source
# File lib/fontist/system_index.rb, line 53 def set_content(path, paths_loader) tap do |content| content.set_path(path) content.set_path_loader(paths_loader) end end
Source
# File lib/fontist/system_index.rb, line 38 def set_path(path) @path = path end
Source
# File lib/fontist/system_index.rb, line 42 def set_path_loader(paths_loader) @paths_loader = paths_loader end
Source
# File lib/fontist/system_index.rb, line 75 def to_file(path) FileUtils.mkdir_p(File.dirname(path)) File.write(path, to_yaml) end
Source
# File lib/fontist/system_index.rb, line 102 def update tap do |col| col.fonts = detect_paths(@paths_loader&.call || []) end end