class Deliver::AppScreenshotValidator
Constants
- ALLOWED_SCREENSHOT_FILE_EXTENSION
Access each array by symbol returned from FastImage.type
- APP_SCREENSHOT_SPEC_URL
Public Class Methods
get_formatted_size(screenshot)
click to toggle source
# File deliver/lib/deliver/app_screenshot_validator.rb, line 102 def self.get_formatted_size(screenshot) size = FastImage.size(screenshot.path) return size.join('x') if size nil end
validate(screenshot, errors)
click to toggle source
Validate a screenshot and inform an error message via `errors` parameter. `errors` is mutated to append the messages and each message should contain the corresponding path to let users know which file is throwing the error.
@param screenshot [AppScreenshot] @param errors [Array<Deliver::AppScreenshotValidator::ValidationError>] Pass an array object to add validation errors when detecting errors.
This will be mutated to add more error objects as validation detects errors.
@return [Boolean] true if given screenshot is valid
# File deliver/lib/deliver/app_screenshot_validator.rb, line 44 def self.validate(screenshot, errors) # Given screenshot will be diagnosed and errors found are accumulated errors_found = [] validate_screen_size(screenshot, errors_found) validate_device_type(screenshot, errors_found) validate_file_extension_and_format(screenshot, errors_found) # Merge errors found into given errors array errors_found.each { |error| errors.push(error) } errors_found.empty? end
validate_device_type(screenshot, errors_found)
click to toggle source
Checking if the device type exists in spaceship Ex: iPhone 6.1 inch isn't supported in App Store Connect but need to have it in there for frameit support
# File deliver/lib/deliver/app_screenshot_validator.rb, line 68 def self.validate_device_type(screenshot, errors_found) if !screenshot.screen_size.nil? && screenshot.device_type.nil? errors_found << ValidationError.new(type: ValidationError::UNACCEPTABLE_DEVICE, path: screenshot.path, debug_info: "Screen size #{screenshot.screen_size} is not accepted. See the specifications to fix #{APP_SCREENSHOT_SPEC_URL}", to_skip: true) end end
validate_file_extension_and_format(screenshot, errors_found)
click to toggle source
# File deliver/lib/deliver/app_screenshot_validator.rb, line 77 def self.validate_file_extension_and_format(screenshot, errors_found) extension = File.extname(screenshot.path).delete('.') valid_file_extensions = ALLOWED_SCREENSHOT_FILE_EXTENSION.values.flatten is_valid_extension = valid_file_extensions.include?(extension) unless is_valid_extension errors_found << ValidationError.new(type: ValidationError::INVALID_FILE_EXTENSION, path: screenshot.path, debug_info: "Only #{valid_file_extensions.join(', ')} are allowed") end format = FastImage.type(screenshot.path) is_extension_matched = ALLOWED_SCREENSHOT_FILE_EXTENSION[format] && ALLOWED_SCREENSHOT_FILE_EXTENSION[format].include?(extension) # This error only appears when file extension is valid if is_valid_extension && !is_extension_matched expected_extension = ALLOWED_SCREENSHOT_FILE_EXTENSION[format].first expected_filename = File.basename(screenshot.path, File.extname(screenshot.path)) + ".#{expected_extension}" errors_found << ValidationError.new(type: ValidationError::FILE_EXTENSION_MISMATCH, path: screenshot.path, debug_info: %(Actual format is "#{format}". Rename the filename to "#{expected_filename}".)) end end
validate_screen_size(screenshot, errors_found)
click to toggle source
# File deliver/lib/deliver/app_screenshot_validator.rb, line 57 def self.validate_screen_size(screenshot, errors_found) if screenshot.screen_size.nil? errors_found << ValidationError.new(type: ValidationError::INVALID_SCREEN_SIZE, path: screenshot.path, debug_info: "Actual size is #{get_formatted_size(screenshot)}. See the specifications to fix #{APP_SCREENSHOT_SPEC_URL}") end end