module ZendeskAppsSupport::Validations::Mime

Constants

UNSUPPORTED_MIME_TYPES

Public Class Methods

call(package) click to toggle source
# File lib/zendesk_apps_support/validations/mime.rb, line 13
def call(package)
  unsupported_files =
    package.files.find_all { |app_file| block_listed?(app_file) }.map(&:relative_path)

  [mime_type_warning(unsupported_files)] if unsupported_files.any?
end

Private Class Methods

block_listed?(app_file) click to toggle source
# File lib/zendesk_apps_support/validations/mime.rb, line 22
def block_listed?(app_file)
  mime_type = MimeMagic.by_magic(app_file.read)

  content_subtype = mime_type.subtype if mime_type
  extension_name = app_file.extension.delete('.')

  ([content_subtype, extension_name] & UNSUPPORTED_MIME_TYPES).any?
end
mime_type_warning(file_names) click to toggle source
# File lib/zendesk_apps_support/validations/mime.rb, line 31
def mime_type_warning(file_names)
  ValidationError.new(
    :unsupported_mime_type_detected,
    file_names: file_names.join(', '),
    count: file_names.count
  )
end