Class: PwaManifestGenerator::ManifestMap
- Inherits:
-
Object
- Object
- PwaManifestGenerator::ManifestMap
- Defined in:
- lib/pwa_manifest_generator/manifest_map.rb
Constant Summary collapse
- KEYS_TYPE_MAP =
{ name: String, short_name: String, description: String, start_url: String, scope: String, theme_color: String, background_color: String, display_setting: String, id: String, iarc_rating_id: String, launch_handler: Hash, categories: Array, orientation: String, display_override: Array, intent: Array, url_handlers: Array, icons: Array, screenshots: Array, prefer_related_applications: [TrueClass, FalseClass], related_applications: Array, scope_extensions: Array, file_handlers: Array, edge_side_panel: String, protocol_handlers: Array, shortcuts: Array, handle_links: [TrueClass, FalseClass] }.freeze
- KEYS =
KEYS_TYPE_MAP.keys.freeze
Class Method Summary collapse
- .default_value_for(key) ⇒ Object
- .ensure_valid_key(instance, key) ⇒ Object
- .key_valid?(key) ⇒ Boolean
Class Method Details
.default_value_for(key) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/pwa_manifest_generator/manifest_map.rb', line 47 def default_value_for(key) case key when :name then 'AppName' when :short_name then 'AppName' when :description then 'A Progressive Web App' when :start_url then '/' when :scope then '/' when :theme_color, :background_color then '#FFFFFF' when :display_setting then 'standalone' when :orientation then 'any' when :display_override then %w[standalone window-controls-overlay minimal-ui] when :categories, :icons, :screenshots, :intent, :url_handlers, :related_applications, :scope_extensions, :file_handlers, :protocol_handlers, :shortcuts then [] when :prefer_related_applications, :handle_links then false end end |
.ensure_valid_key(instance, key) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/pwa_manifest_generator/manifest_map.rb', line 20 def ensure_valid_key(instance, key) raise ArgumentError, "Unknown key: #{key}" unless KEYS.include?(key) case key when :launch_handler, :intent, :url_handlers # Custom handler validation can be implemented here when :prefer_related_applications, :handle_links unless KEYS_TYPE_MAP[key].include?(instance.send(key).class) raise ArgumentError, "Invalid type for #{key}: #{instance.send(key).class}" end else unless instance.send(key).is_a?(KEYS_TYPE_MAP[key]) raise ArgumentError, "Invalid type for #{key}: #{instance.send(key).class}" end if instance.send(key).is_a?(Array) instance.instance_variable_set("@#{key}", HTMLArray.new(instance.send(key))) end end true end |
.key_valid?(key) ⇒ Boolean
43 44 45 |
# File 'lib/pwa_manifest_generator/manifest_map.rb', line 43 def key_valid?(key) KEYS.include?(key) end |