Class: Plum::SiteArchive::Importer
- Inherits:
-
Object
- Object
- Plum::SiteArchive::Importer
- Defined in:
- app/services/plum/site_archive.rb
Instance Method Summary collapse
- #import(name: nil, domain: nil) ⇒ Object
-
#initialize(path) ⇒ Importer
constructor
A new instance of Importer.
Constructor Details
#initialize(path) ⇒ Importer
Returns a new instance of Importer.
116 117 118 119 120 |
# File 'app/services/plum/site_archive.rb', line 116 def initialize(path) @path = Pathname(path). @maps = Hash.new { |hash, key| hash[key] = {} } @uploaded_blobs = [] end |
Instance Method Details
#import(name: nil, domain: nil) ⇒ Object
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'app/services/plum/site_archive.rb', line 122 def import(name: nil, domain: nil) raise InvalidArchive, "Archive does not exist: #{path}" unless path.file? Zip::File.open(path) do |zip| @zip = zip @data = parse_manifest(zip) validate_manifest! ActiveRecord::Base.transaction { import_site(name:, domain:) } end rescue StandardError => error cleanup_uploaded_files raise unless error.is_a?(Zip::Error) || error.is_a?(JSON::ParserError) raise InvalidArchive, error. ensure @zip = nil end |