class Fontist::InstallLocations::BaseLocation
Abstract base class for font installation locations
This class provides the foundation for all installation location types, implementing the core logic for:
-
Managed vs non-managed location detection
-
Fontinstallation with duplicate prevention -
Unique filename generation for non-managed locations
-
Educational warning messages
-
Indexmanagement integration
## Managed vs Non-Managed Locations
**Fontist-Managed Locations** (safe to replace fonts):
-
Fontistlibrary: ~/.fontist/fonts/{formula-key}/ -
User default: ~/Library/Fonts/fontist/
-
System default: /Library/Fonts/fontist/
**Non-Managed Locations** (never replace existing fonts):
-
Custom user root: ~/Library/Fonts/ (when FONTIST_USER_FONTS_PATH=~/Library/Fonts)
-
Custom system root: /Library/Fonts/ (when FONTIST_SYSTEM_FONTS_PATH=/Library/Fonts)
## Subclass Requirements
Subclasses must implement:
-
base_path: Returns Pathname for installation directory -
location_type: Returns Symbol (:fontist, :user, :system) -
index: Returns index instance for this location
Attributes
Public Class Methods
Source
# File lib/fontist/install_locations/base_location.rb, line 37 def initialize(formula) @formula = formula end
Public Instance Methods
Source
# File lib/fontist/install_locations/base_location.rb, line 45 def base_path raise NotImplementedError, "#{self.class} must implement #base_path" end
Returns the base installation path for this location @return [Pathname] Base installation directory
Source
# File lib/fontist/install_locations/base_location.rb, line 123 def find_fonts(font_name, style = nil) index.find(font_name, style) end
Finds fonts by name and optional style at this location
@param font_name [String] Font family name @param style [String, nil] Optional style (e.g., โRegularโ, โBoldโ) @return [Array<SystemIndexFont>, nil] Found fonts or nil
Source
# File lib/fontist/install_locations/base_location.rb, line 113 def font_exists?(filename) path = font_path(filename).to_s index.font_exists?(path) end
Checks if a font exists at this location
@param filename [String] Font filename to check @return [Boolean] true if font exists
Source
# File lib/fontist/install_locations/base_location.rb, line 60 def font_path(filename) base_path.join(filename) end
Returns full path for a font file @param filename [String] The font filename @return [Pathname] Full path where font should be installed
Source
# File lib/fontist/install_locations/base_location.rb, line 73 def install_font(source_path, target_filename) target = font_path(target_filename) # Check if font already exists at this location if font_exists?(target_filename) if managed_location? # Safe to replace in managed locations replace_font(source_path, target) else # Non-managed: use unique name to avoid overwriting user/system fonts unique_filename = generate_unique_filename(target_filename) install_with_warning(source_path, unique_filename, original_path: target) end else # New installation - simple case simple_install(source_path, target) end end
Installs a font file to this location
Handles managed vs non-managed logic:
-
Managed locations: Replace existing font if present
-
Non-managed locations: Generate unique name to avoid conflicts
@param source_path [String] Path to source font file @param target_filename [String] Desired filename for font @return [String, nil] Installed path or nil if skipped
Source
# File lib/fontist/install_locations/base_location.rb, line 51 def location_type raise NotImplementedError, "#{self.class} must implement #location_type" end
Returns the location type identifier @return [Symbol] :fontist, :user, or :system
Source
# File lib/fontist/install_locations/base_location.rb, line 137 def permission_warning nil end
Returns warning message for installations requiring permissions
@return [String, nil] Warning message or nil
Source
# File lib/fontist/install_locations/base_location.rb, line 130 def requires_elevated_permissions? false end
Checks if this location requires elevated permissions
@return [Boolean] true if sudo/admin rights needed
Source
# File lib/fontist/install_locations/base_location.rb, line 97 def uninstall_font(filename) target = font_path(filename) return nil unless File.exist?(target) File.delete(target) # Update this location's index index.remove_font(target.to_s) target.to_s end
Uninstalls a font file from this location
@param filename [String] Font filename to remove @return [String, nil] Deleted path or nil if not found
Protected Instance Methods
Source
# File lib/fontist/install_locations/base_location.rb, line 147 def index raise NotImplementedError, "#{self.class} must implement #index" end
Returns the index instance for this location Must be implemented by subclasses
@return [Object] Index instance (FontistIndex, UserIndex, or SystemIndex)
Source
# File lib/fontist/install_locations/base_location.rb, line 157 def managed_location? true # Default: assume managed unless overridden end