Class: MigrationService
- Inherits:
-
Object
- Object
- MigrationService
- Defined in:
- app/services/migration_service.rb
Defined Under Namespace
Classes: ArchiveValidationFailed, MigrationAlreadyExists, SelfMigrationNotAllowed
Instance Attribute Summary collapse
-
#archive_path ⇒ Object
readonly
Returns the value of attribute archive_path.
-
#new_user_name ⇒ Object
readonly
Returns the value of attribute new_user_name.
-
#opts ⇒ Object
readonly
Returns the value of attribute opts.
Instance Method Summary collapse
-
#initialize(archive_path, new_user_name, opts = {}) ⇒ MigrationService
constructor
A new instance of MigrationService.
-
#only_import? ⇒ Boolean
when old person can't be resolved we still import data but we don't create&perform AccountMigration instance.
- #perform! ⇒ Object
- #self_import? ⇒ Boolean
- #validate ⇒ Object
Constructor Details
#initialize(archive_path, new_user_name, opts = {}) ⇒ MigrationService
Returns a new instance of MigrationService.
8 9 10 11 12 |
# File 'app/services/migration_service.rb', line 8 def initialize(archive_path, new_user_name, opts={}) @archive_path = archive_path @new_user_name = new_user_name @opts = opts end |
Instance Attribute Details
#archive_path ⇒ Object (readonly)
Returns the value of attribute archive_path.
4 5 6 |
# File 'app/services/migration_service.rb', line 4 def archive_path @archive_path end |
#new_user_name ⇒ Object (readonly)
Returns the value of attribute new_user_name.
4 5 6 |
# File 'app/services/migration_service.rb', line 4 def new_user_name @new_user_name end |
#opts ⇒ Object (readonly)
Returns the value of attribute opts.
4 5 6 |
# File 'app/services/migration_service.rb', line 4 def opts @opts end |
Instance Method Details
#only_import? ⇒ Boolean
when old person can't be resolved we still import data but we don't create&perform AccountMigration instance
38 39 40 |
# File 'app/services/migration_service.rb', line 38 def only_import? old_person.nil? end |
#perform! ⇒ Object
23 24 25 26 27 28 29 |
# File 'app/services/migration_service.rb', line 23 def perform! find_or_create_user import_archive run_migration ensure remove_intermediate_file end |
#self_import? ⇒ Boolean
31 32 33 34 35 |
# File 'app/services/migration_service.rb', line 31 def self_import? source_diaspora_id = archive_validator. target_diaspora_id = "#{new_user_name}#{User.diaspora_id_host}" source_diaspora_id == target_diaspora_id end |
#validate ⇒ Object
14 15 16 17 18 19 20 21 |
# File 'app/services/migration_service.rb', line 14 def validate return unless archive_file_exists? archive_validator.validate raise ArchiveValidationFailed, errors.join("\n") if errors.any? raise MigrationAlreadyExists if AccountMigration.where(old_person: old_person).any? raise SelfMigrationNotAllowed if self_import? end |