Class: Fontist::Manifest
- Inherits:
-
Lutaml::Model::Collection
- Object
- Lutaml::Model::Collection
- Fontist::Manifest
show all
- Defined in:
- lib/fontist/manifest.rb
Overview
Manifest class for managing font manifests.
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.font_class ⇒ Object
108
109
110
|
# File 'lib/fontist/manifest.rb', line 108
def self.font_class
ManifestFont
end
|
.from_file(path, locations: false) ⇒ Object
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
|
# File 'lib/fontist/manifest.rb', line 75
def self.from_file(path, locations: false)
Fontist.ui.debug("Manifest: #{path}")
unless File.exist?(path)
raise Fontist::Errors::ManifestCouldNotBeFoundError,
"Manifest file not found: #{path}"
end
file_content = File.read(path).strip
if file_content.empty?
raise Fontist::Errors::ManifestCouldNotBeReadError,
"Manifest file is empty: #{path}"
end
manifest_model = begin
from_yaml(file_content)
rescue StandardError => e
raise Fontist::Errors::ManifestCouldNotBeReadError,
"Manifest file could not be read: #{e.message}"
end
manifest_model.to_response(locations: locations)
end
|
.from_hash(data, options = {}) ⇒ Object
100
101
102
103
104
105
106
|
# File 'lib/fontist/manifest.rb', line 100
def self.from_hash(data, options = {})
locations = options.delete(:locations) || false
model = super(data, options)
model.to_response(locations: locations)
end
|
Instance Method Details
#fonts_casted ⇒ Object
112
113
114
115
116
|
# File 'lib/fontist/manifest.rb', line 112
def fonts_casted
Array(fonts).map do |font|
self.class.font_class === font ? font : self.class.font_class.new(font.to_h)
end
end
|
#install(confirmation: "no", hide_licenses: false, no_progress: false) ⇒ Object
118
119
120
121
122
123
124
125
126
127
|
# File 'lib/fontist/manifest.rb', line 118
def install(confirmation: "no", hide_licenses: false, no_progress: false)
fonts_casted.each do |font|
paths = font.group_paths
if paths.length < fonts_casted.length
font.install(confirmation: confirmation,
hide_licenses: hide_licenses, no_progress: no_progress)
end
end
to_response
end
|
#to_file(path) ⇒ Object
139
140
141
142
|
# File 'lib/fontist/manifest.rb', line 139
def to_file(path)
FileUtils.mkdir_p(File.dirname(path))
File.write(path, to_yaml)
end
|
#to_response(locations: false) ⇒ Object
129
130
131
132
133
134
135
136
137
|
# File 'lib/fontist/manifest.rb', line 129
def to_response(locations: false)
return self if fonts_casted.any?(&:group_paths_empty?) && !locations
ManifestResponse.new.tap do |response|
response.fonts = fonts_casted.map do |font|
font.to_response(locations: locations)
end
end
end
|