module WarpEngine::Shelves
Shelves: folders the engine keeps in step with the catalog, holding the latest build of every public title of one platform under a fixed, versionless name, plus an INDEX_FILE listing them. They serve clients that cannot read the JSON API (a C64 store over HTTP, a DOS installer over FTP).
shelf :c64, kind: "cartridge", path: "shelves/C64", extension: ".PRG", name_length: 16
The definitions live in WarpEngine.config.shelves; WarpEngine::ShelfService writes the folders.
Constants
- EXTENSION_PATTERN
-
The form a flat shelf’s extension must have, e.g.
.PRG. - INDEX_FILE
-
The name of the index file written into every shelf.
- KEYS
-
The keys a shelf definition accepts.
- LAYOUTS
-
The shelf layouts:
flat(one file a title) andfolders(one folder a title). - NAME_PATTERN
-
The characters a shelf file or folder name may consist of.
- Shelf
-
One validated shelf definition.
- platform
-
the platform name
- kinds
-
the release asset kinds it takes
- layout
-
flatorfolders - path
-
the folder, relative to
file_container_path - extension
-
the extension of a flat shelf’s files, in capitals
- name_length
-
the longest file name (extension included) or folder name
- statuses
-
the software statuses listed; empty means the default visible ones
- urls
-
where the host serves the folder
- URL_SCHEMES
-
The URL schemes a shelf’s
urlsmay use.
Public Class Methods
Source
# File lib/warp_engine/shelves.rb, line 80 def all Array(WarpEngine.config.shelves).map { |definition| build(definition) } end
Returns every configured shelf as a Shelf. Raises ConfigurationError on an invalid definition.
Source
# File lib/warp_engine/shelves.rb, line 85 def any? = Array(WarpEngine.config.shelves).any?
Returns true when any shelf is configured.
Source
# File lib/warp_engine/shelves.rb, line 129 def descriptors all.map do |shelf| { platform: shelf.platform, kinds: shelf.kinds, layout: shelf.layout, index: INDEX_FILE, urls: shelf.urls } end rescue ConfigurationError [] end
Returns a Hash for each shelf (platform, kinds, layout, index, urls), as GET /api/service lists them; an empty Array when the configuration is invalid.
Source
# File lib/warp_engine/shelves.rb, line 88 def for_platform(platform) all.select { |shelf| shelf.platform == platform.to_s } end
Returns the shelves of platform.
Source
# File lib/warp_engine/shelves.rb, line 108 def normalize_name(value) I18n.transliterate(value.to_s).upcase.gsub(/[^A-Z0-9-]+/, "-").squeeze("-").gsub(/\A-+|-+\z/, "") end
Returns value as a shelf name: transliterated to ASCII, upcased, every run of other characters than A-Z 0-9 - turned into one dash, leading and trailing dashes removed.
Source
# File lib/warp_engine/shelves.rb, line 116 def refresh(platform: nil) return [] unless any? shelves = platform.nil? ? all : for_platform(platform) shelves.map { |shelf| WarpEngine::ShelfService.new(shelf).sync! } rescue StandardError => e Rails.logger.error("[WarpEngine::Shelves] refresh #{platform || 'all'}: #{e.class}: #{e.message}") [] end
Syncs the shelves of platform (every shelf when nil) with the catalog through WarpEngine::ShelfService#sync!, rewriting their folders. Returns the sync results; returns an empty Array when no shelf is configured, or logs the error and returns an empty Array when the sync fails.
Source
# File lib/warp_engine/shelves.rb, line 95 def validate! shelves = all raise ConfigurationError, "shelves need the :local storage adapter" if shelves.any? && !WarpEngine::Storage.local? duplicates = shelves.group_by(&:path).select { |_, group| group.size > 1 }.keys raise ConfigurationError, "two shelves share the path #{duplicates.first}" if duplicates.any? shelves end
Builds and checks every shelf, and returns them. Raises ConfigurationError on an invalid definition, when shelves are configured with a storage adapter other than the local one, or when two shelves share a path.