class PrelandsRails::CreateSimpleSource::CheckZipFiles
Проверит наличие файлов и директорий в архиве с исходниками преленда:
* должен быть файл index.js * должен быть файл index.css * должна быть директория images/ * должны быть все языковые файлы index_<lang>.html, согласно локалям преленда * размер любого файла не должен превышать 8мб
Constants
- MAX_SIZE
Public Instance Methods
act()
click to toggle source
# File lib/prelands_rails/create_simple_source/check_zip_files.rb, line 49 def act # если нет хотя бы одного файла - уходим с ошибкой absents = detect_absent_files @expected_files, incoming_files if absents.present? fail! errors: absents.join('; ') end # считываем в память файлы, которые необходимо валидировать rx1 = /\.(css|js|html)/ files = @expected_files.select { |file| file.ftype == :file && file.name =~ rx1 } context.files_content, context.tmp_paths = read_into_memory files, context.archive.tempfile # фиксируем список всех файлов из архива context.incoming_files = incoming_files end
incoming_files()
click to toggle source
# File lib/prelands_rails/create_simple_source/check_zip_files.rb, line 65 def incoming_files @incoming_files ||= Zip::File.open(context.archive.tempfile) do |zipfile| zipfile.map do |file| if file.size > MAX_SIZE fail! errors: 'File too large when extracted (must be less than %s bytes)' % MAX_SIZE end { ftype: file.ftype, name: file.name } end end.map(&:to_struct).freeze end