Class: PrelandsRails::CreateSimpleSource::CheckZipFiles
- Inherits:
-
Object
- Object
- PrelandsRails::CreateSimpleSource::CheckZipFiles
- Includes:
- Interactor, Interactor::Contracts, AbstractInteractor, Base, DetectAbsentFiles, ExtractFiles
- Defined in:
- lib/prelands_rails/create_simple_source/check_zip_files.rb,
lib/prelands_rails/create_simple_source/check_zip_files/extract_files.rb,
lib/prelands_rails/create_simple_source/check_zip_files/detect_absent_files.rb
Overview
Проверит наличие файлов и директорий в архиве с исходниками преленда:
* должен быть файл index.js
* должен быть файл index.css
* должна быть директория images/
* должны быть все языковые файлы index_<lang>.html, согласно локалям преленда
* размер любого файла не должен превышать 8мб
Defined Under Namespace
Modules: DetectAbsentFiles, ExtractFiles
Instance Method Summary collapse
Methods included from ExtractFiles
Methods included from DetectAbsentFiles
Methods included from AbstractInteractor
Instance Method Details
#act ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# 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 ⇒ Object
65 66 67 68 69 70 71 72 73 74 |
# 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 |