Class: Fontist::InstallLocations::BaseLocation
- Inherits:
-
Object
- Object
- Fontist::InstallLocations::BaseLocation
- Defined in:
- lib/fontist/install_locations/base_location.rb
Overview
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
-
Font installation with duplicate prevention
-
Unique filename generation for non-managed locations
-
Educational warning messages
-
Index management integration
## Managed vs Non-Managed Locations
**Fontist-Managed Locations** (safe to replace fonts):
-
Fontist library: ~/.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
Direct Known Subclasses
Instance Attribute Summary collapse
-
#formula ⇒ Object
readonly
Returns the value of attribute formula.
Instance Method Summary collapse
-
#base_path ⇒ Pathname
Returns the base installation path for this location.
-
#find_fonts(font_name, style = nil) ⇒ Array<SystemIndexFont>?
Finds fonts by name and optional style at this location.
-
#font_exists?(filename) ⇒ Boolean
Checks if a font exists at this location.
-
#font_path(filename) ⇒ Pathname
Returns full path for a font file.
-
#initialize(formula) ⇒ BaseLocation
constructor
A new instance of BaseLocation.
-
#install_font(source_path, target_filename) ⇒ String?
Installs a font file to this location.
-
#location_type ⇒ Symbol
Returns the location type identifier.
-
#permission_warning ⇒ String?
Returns warning message for installations requiring permissions.
-
#requires_elevated_permissions? ⇒ Boolean
Checks if this location requires elevated permissions.
-
#uninstall_font(filename) ⇒ String?
Uninstalls a font file from this location.
Constructor Details
#initialize(formula) ⇒ BaseLocation
Returns a new instance of BaseLocation.
37 38 39 |
# File 'lib/fontist/install_locations/base_location.rb', line 37 def initialize(formula) @formula = formula end |
Instance Attribute Details
#formula ⇒ Object (readonly)
Returns the value of attribute formula.
35 36 37 |
# File 'lib/fontist/install_locations/base_location.rb', line 35 def formula @formula end |
Instance Method Details
#base_path ⇒ Pathname
Returns the base installation path for this location
45 46 47 |
# File 'lib/fontist/install_locations/base_location.rb', line 45 def base_path raise NotImplementedError, "#{self.class} must implement #base_path" end |
#find_fonts(font_name, style = nil) ⇒ Array<SystemIndexFont>?
Finds fonts by name and optional style at this location
123 124 125 |
# File 'lib/fontist/install_locations/base_location.rb', line 123 def find_fonts(font_name, style = nil) index.find(font_name, style) end |
#font_exists?(filename) ⇒ Boolean
Checks if a font exists at this location
113 114 115 116 |
# 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 |
#font_path(filename) ⇒ Pathname
Returns full path for a font file
60 61 62 |
# File 'lib/fontist/install_locations/base_location.rb', line 60 def font_path(filename) base_path.join(filename) end |
#install_font(source_path, target_filename) ⇒ String?
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
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# 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 |
#location_type ⇒ Symbol
Returns the location type identifier
51 52 53 |
# File 'lib/fontist/install_locations/base_location.rb', line 51 def location_type raise NotImplementedError, "#{self.class} must implement #location_type" end |
#permission_warning ⇒ String?
Returns warning message for installations requiring permissions
137 138 139 |
# File 'lib/fontist/install_locations/base_location.rb', line 137 def nil end |
#requires_elevated_permissions? ⇒ Boolean
Checks if this location requires elevated permissions
130 131 132 |
# File 'lib/fontist/install_locations/base_location.rb', line 130 def false end |
#uninstall_font(filename) ⇒ String?
Uninstalls a font file from this location
97 98 99 100 101 102 103 104 105 106 107 |
# 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 |