module Fontist::Indexes::IndexMixin
Public Class Methods
Source
# File lib/fontist/indexes/index_mixin.rb, line 4 def self.included(base) base.extend(ClassMethods) end
Public Instance Methods
Source
# File lib/fontist/indexes/index_mixin.rb, line 41 def add_formula(formula) raise unless formula.is_a?(Formula) formula.all_fonts.each do |font| font.styles.each do |style| add_index_formula(style, formula.path) end end entries end
Source
# File lib/fontist/indexes/index_mixin.rb, line 57 def add_index_formula(style, formula_path) key = index_key_for_style(style) raise if key.nil? || key.empty? key = normalize_key(key) formula_path = Array(formula_path) paths = formula_path.map { |p| relative_formula_path(p) } if index_formula(key) index_formula(key).formula_path.concat(paths).uniq! return end entries << FormulaKeyToPath.new( key: key, formula_path: paths, ) end
Source
# File lib/fontist/indexes/index_mixin.rb, line 31 def build Formula.all.each do |formula| add_formula(formula) end to_file self end
Source
# File lib/fontist/indexes/index_mixin.rb, line 53 def index_key_for_style(_style) raise NotImplementedError, "index_key_for_style(style) must be implemented in including class" end
Source
# File lib/fontist/indexes/index_mixin.rb, line 76 def load_formulas(key) index_formulas(key).flat_map(&:to_full) end
Source
# File lib/fontist/indexes/index_mixin.rb, line 80 def load_index_formulas(key) index_formulas(key) end
Source
# File lib/fontist/indexes/index_mixin.rb, line 84 def to_file(file_path = self.class.path) # Use default path if file_path is nil file_path = self.class.path if file_path.nil? # puts "Writing index to #{file_path}" FileUtils.mkdir_p(File.dirname(file_path)) File.write(file_path, to_yaml) end