Class: ArchiveValidator

Inherits:
Object
  • Object
show all
Includes:
ArchiveImporter::ArchiveHelper
Defined in:
lib/archive_validator.rb,
lib/archive_validator/base_validator.rb,
lib/archive_validator/post_validator.rb,
lib/archive_validator/entities_helper.rb,
lib/archive_validator/posts_validator.rb,
lib/archive_validator/schema_validator.rb,
lib/archive_validator/contact_validator.rb,
lib/archive_validator/contacts_validator.rb,
lib/archive_validator/relayable_validator.rb,
lib/archive_validator/collection_validator.rb,
lib/archive_validator/relayables_validator.rb,
lib/archive_validator/own_relayable_validator.rb,
lib/archive_validator/others_relayables_validator.rb,
lib/archive_validator/author_private_key_validator.rb

Overview

ArchiveValidator checks for errors in archive. It also find non-critical problems and fixes them in the archive hash so that the ArchiveImporter doesn't have to handle this issues. Non-critical problems found are indicated as warnings. Also it performs necessary data fetch where required.

Defined Under Namespace

Modules: EntitiesHelper Classes: AuthorPrivateKeyValidator, BaseValidator, CollectionValidator, ContactValidator, ContactsValidator, OthersRelayablesValidator, OwnRelayableValidator, PostValidator, PostsValidator, RelayableValidator, RelayablesValidator, SchemaValidator

Instance Method Summary collapse

Methods included from ArchiveImporter::ArchiveHelper

#archive_author_diaspora_id, #contact_groups, #contacts, #others_relayables, #person, #post_subscriptions, #posts, #private_key, #relayables, #serialized_private_key

Constructor Details

#initialize(archive) ⇒ ArchiveValidator

Returns a new instance of ArchiveValidator.


11
12
13
# File 'lib/archive_validator.rb', line 11

def initialize(archive)
  @archive = archive
end

Instance Method Details

#archive_hashObject


32
33
34
# File 'lib/archive_validator.rb', line 32

def archive_hash
  @archive_hash ||= Yajl::Parser.new.parse(archive)
end

#errorsObject


24
25
26
# File 'lib/archive_validator.rb', line 24

def errors
  @errors ||= []
end

#validateObject


15
16
17
18
19
20
21
22
# File 'lib/archive_validator.rb', line 15

def validate
  run_validators(CRITICAL_VALIDATORS, errors)
  run_validators(NON_CRITICAL_VALIDATORS, warnings)
rescue KeyError => e
  errors.push("Missing mandatory data: #{e}")
rescue Yajl::ParseError => e
  errors.push("Bad JSON provided: #{e}")
end

#warningsObject


28
29
30
# File 'lib/archive_validator.rb', line 28

def warnings
  @warnings ||= []
end