Class: Fontist::InstallLocation
- Inherits:
-
Object
- Object
- Fontist::InstallLocation
- Defined in:
- lib/fontist/install_location.rb
Overview
Factory for creating font installation location objects
Provides a unified interface for creating location-specific installation handlers. Each location type (fontist, user, system) has its own class that manages font installation, index updates, and duplicate prevention.
## Location Types
-
fontist: ~/.fontist/fonts/formula-key/ (default, isolated, safe)
-
user: Platform-specific user font directory with ‘fontist’ subdirectory
-
system: Platform-specific system font directory with ‘fontist’ subdirectory
## Usage
# Create a specific location
location = InstallLocation.create(formula, location_type: :user)
location.install_font(source_path, "Roboto-Regular.ttf")
# Get all possible locations for a formula
locations = InstallLocation.all_locations(formula)
locations.each { |loc| puts loc.base_path }
## Platform-Specific Paths
### macOS
-
user: ~/Library/Fonts/fontist/
-
system (regular): /Library/Fonts/fontist/
-
system (supplementary): /System/Library/Assets*/com_apple_MobileAsset_Font*/asset.asset/AssetData/
### Linux
-
user: ~/.local/share/fonts/fontist/
-
system: /usr/local/share/fonts/fontist/
### Windows
-
user: %LOCALAPPDATA%MicrosoftWindowsFontsfontist\
-
system: %windir%Fontsfontist\
## Customization
Override paths via environment variables or config:
-
FONTIST_USER_FONTS_PATH - Custom user font path
-
FONTIST_SYSTEM_FONTS_PATH - Custom system font path
Or use config commands:
fontist config set user_fonts_path /custom/path
fontist config set system_fonts_path /custom/path
Class Method Summary collapse
-
.all_locations(formula) ⇒ Array<BaseLocation>
Returns all possible location instances for a formula.
-
.create(formula, location_type: nil) ⇒ BaseLocation
Creates a location instance for the specified type.
-
.parse_location_type(value) ⇒ Symbol
Parses and validates location type.
Class Method Details
.all_locations(formula) ⇒ Array<BaseLocation>
Returns all possible location instances for a formula
Useful for:
-
Searching across all locations for existing fonts
-
Displaying all possible installation paths
-
Uninstalling from all locations
96 97 98 99 100 101 102 |
# File 'lib/fontist/install_location.rb', line 96 def self.all_locations(formula) [ InstallLocations::FontistLocation.new(formula), InstallLocations::UserLocation.new(formula), InstallLocations::SystemLocation.new(formula), ] end |
.create(formula, location_type: nil) ⇒ BaseLocation
Creates a location instance for the specified type
66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/fontist/install_location.rb', line 66 def self.create(formula, location_type: nil) type = parse_location_type(location_type) case type when :fontist InstallLocations::FontistLocation.new(formula) when :user InstallLocations::UserLocation.new(formula) when :system InstallLocations::SystemLocation.new(formula) else raise ArgumentError, "Unknown location type: #{type}" end end |
.parse_location_type(value) ⇒ Symbol
Parses and validates location type
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/fontist/install_location.rb', line 108 def self.parse_location_type(value) # Default to configured location if no value provided return Config.fonts_install_location if value.nil? # Normalize string input case value.to_s.downcase.tr("_", "-") when "fontist", "fontist-library" :fontist when "user" :user when "system" :system else # Invalid input - show error and fall back to default Fontist.ui.error(<<~ERROR.strip) Invalid install location: '#{value}' Valid options: fontist, user, system Using default location: fontist ERROR :fontist end end |