Class: Zui::Dist::Config
- Inherits:
-
Object
- Object
- Zui::Dist::Config
- Defined in:
- lib/zui/dist_config.rb
Instance Attribute Summary collapse
-
#categories ⇒ Object
readonly
Returns the value of attribute categories.
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#homepage ⇒ Object
readonly
Returns the value of attribute homepage.
-
#icons ⇒ Object
readonly
Returns the value of attribute icons.
-
#identifier ⇒ Object
readonly
Returns the value of attribute identifier.
-
#license ⇒ Object
readonly
Returns the value of attribute license.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#publisher ⇒ Object
readonly
Returns the value of attribute publisher.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Instance Method Summary collapse
- #icon_path(project, platform) ⇒ Object
-
#initialize(name:, identifier:, version:, publisher:, description:, license:, homepage:, icons:, categories:) ⇒ Config
constructor
A new instance of Config.
- #package_name ⇒ Object
- #validate!(project:, platform:) ⇒ Object
Constructor Details
#initialize(name:, identifier:, version:, publisher:, description:, license:, homepage:, icons:, categories:) ⇒ Config
Returns a new instance of Config.
19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/zui/dist_config.rb', line 19 def initialize(name:, identifier:, version:, publisher:, description:, license:, homepage:, icons:, categories:) @name = name @identifier = identifier @version = version @publisher = publisher @description = description @license = license @homepage = homepage @icons = icons.transform_keys(&:to_sym).transform_values(&:to_s).freeze @categories = categories.map(&:to_s).freeze freeze end |
Instance Attribute Details
#categories ⇒ Object (readonly)
Returns the value of attribute categories.
16 17 18 |
# File 'lib/zui/dist_config.rb', line 16 def categories @categories end |
#description ⇒ Object (readonly)
Returns the value of attribute description.
16 17 18 |
# File 'lib/zui/dist_config.rb', line 16 def description @description end |
#homepage ⇒ Object (readonly)
Returns the value of attribute homepage.
16 17 18 |
# File 'lib/zui/dist_config.rb', line 16 def homepage @homepage end |
#icons ⇒ Object (readonly)
Returns the value of attribute icons.
16 17 18 |
# File 'lib/zui/dist_config.rb', line 16 def icons @icons end |
#identifier ⇒ Object (readonly)
Returns the value of attribute identifier.
16 17 18 |
# File 'lib/zui/dist_config.rb', line 16 def identifier @identifier end |
#license ⇒ Object (readonly)
Returns the value of attribute license.
16 17 18 |
# File 'lib/zui/dist_config.rb', line 16 def license @license end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
16 17 18 |
# File 'lib/zui/dist_config.rb', line 16 def name @name end |
#publisher ⇒ Object (readonly)
Returns the value of attribute publisher.
16 17 18 |
# File 'lib/zui/dist_config.rb', line 16 def publisher @publisher end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
16 17 18 |
# File 'lib/zui/dist_config.rb', line 16 def version @version end |
Instance Method Details
#icon_path(project, platform) ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/zui/dist_config.rb', line 66 def icon_path(project, platform) os = platform.os relative = icons[os] raise ArgumentError, "#{CONFIG_FILE} must declare icon #{os}: \"path\"" if relative.nil? || relative.empty? if Pathname.new(relative).absolute? || relative.include?("\0") raise ArgumentError, "#{CONFIG_FILE} #{os} icon must be a project-relative path" end path = File.(relative, project) unless File.file?(path) raise ArgumentError, "#{CONFIG_FILE} #{os} icon was not found: #{relative}" end real_path = File.realpath(path) unless real_path.start_with?("#{File.realpath(project)}#{File::SEPARATOR}") raise ArgumentError, "#{CONFIG_FILE} #{os} icon must stay inside the project" end extension = File.extname(real_path).downcase allowed = PLATFORM_ICON_EXTENSIONS.fetch(os) unless allowed.include?(extension) raise ArgumentError, "#{CONFIG_FILE} #{os} icon must use #{allowed.join(' or ')}" end raise ArgumentError, "#{CONFIG_FILE} icon is too large" if File.size(real_path) > 20 * 1024 * 1024 validate_icon_signature!(real_path, extension) real_path end |
#package_name ⇒ Object
59 60 61 62 63 64 |
# File 'lib/zui/dist_config.rb', line 59 def package_name value = name.downcase.gsub(/[^a-z0-9]+/, "-").gsub(/\A-|-\z/, "") raise ArgumentError, "#{CONFIG_FILE} name must contain letters or numbers" if value.empty? value.length < 2 ? "zui-#{value}" : value end |
#validate!(project:, platform:) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/zui/dist_config.rb', line 33 def validate!(project:, platform:) project = File.realpath(project) validate_text!("name", name, maximum: 100) validate_text!("publisher", publisher, maximum: 200) validate_text!("description", description, maximum: 500) validate_text!("license", license, maximum: 100) if homepage validate_text!("homepage", homepage, maximum: 500) unless homepage.match?(%r{\Ahttps?://[^\s]+\z}) raise ArgumentError, "#{CONFIG_FILE} homepage must be an HTTP or HTTPS URL" end end unless identifier.to_s.match?(/\A[a-z][a-z0-9]*(?:\.[a-z][a-z0-9-]*)+\z/) raise ArgumentError, "#{CONFIG_FILE} identifier must be a lowercase reverse-DNS name" end unless version.to_s.match?(/\A\d+\.\d+\.\d+\z/) raise ArgumentError, "#{CONFIG_FILE} version must have three numeric parts, such as 1.2.0" end if categories.empty? || categories.any? { |value| !value.match?(/\A[A-Za-z][A-Za-z0-9-]*\z/) } raise ArgumentError, "#{CONFIG_FILE} categories must contain portable desktop category names" end icon_path(project, platform) self end |