Class: SpatialFeatures::Importers::UnreadableFile

Inherits:
Base
  • Object
show all
Defined in:
lib/spatial_features/importers/unreadable_file.rb

Overview

Stands in for a source file we couldn't read at all — an archive with no map data in it, a shapefile missing a component, an unsupported format. It behaves like an importer that found nothing and carries the reason as a warning, so the files uploaded beside it still import and the user is told which file was skipped and why.

When every source is unreadable the import ends up empty and update_features! raises EmptyImportError with these warnings as the reason, the same way a file containing only NetworkLinks does.

Constant Summary collapse

UNREADABLE =

Fallbacks for failures that didn't come from an importer, whose own messages would mean nothing to the person who uploaded the file — and in the missing-file case would put a server filesystem path in front of them.

"This file couldn't be opened. It may be damaged, or saved in a format we can't read.".freeze
MISSING =
"This file is no longer available on the server. Please upload it again.".freeze

Instance Attribute Summary

Attributes inherited from Base

#errors, #source_identifier, #warnings

Instance Method Summary collapse

Methods inherited from Base

create_all, #features

Constructor Details

#initialize(data, error, **options) ⇒ UnreadableFile

Returns a new instance of UnreadableFile.



20
21
22
23
24
# File 'lib/spatial_features/importers/unreadable_file.rb', line 20

def initialize(data, error, **options)
  super(data, **options)
  self.source_identifier ||= ::File.basename(data.to_s)
  @warnings << reason_for(error)
end

Instance Method Details

#cache_keyObject

Include the reason so that fixing an importer (or the user re-uploading) produces a different key and the record re-imports rather than matching its cached hash.



28
29
30
# File 'lib/spatial_features/importers/unreadable_file.rb', line 28

def cache_key
  @cache_key ||= Digest::MD5.hexdigest([@data, *@warnings].join)
end