Class: MigrationService

Inherits:
Object
  • Object
show all
Defined in:
app/services/migration_service.rb

Defined Under Namespace

Classes: ArchiveValidationFailed, MigrationAlreadyExists

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(archive_path, new_user_name) ⇒ MigrationService

Returns a new instance of MigrationService.


7
8
9
10
# File 'app/services/migration_service.rb', line 7

def initialize(archive_path, new_user_name)
  @archive_path = archive_path
  @new_user_name = new_user_name
end

Instance Attribute Details

#archive_pathObject (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_nameObject (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

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

Returns:

  • (Boolean)

25
26
27
# File 'app/services/migration_service.rb', line 25

def only_import?
  old_person.nil?
end

#perform!Object


18
19
20
21
22
# File 'app/services/migration_service.rb', line 18

def perform!
  find_or_create_user
  import_archive
  run_migration
end

#validateObject


12
13
14
15
16
# File 'app/services/migration_service.rb', line 12

def validate
  archive_validator.validate
  raise ArchiveValidationFailed, errors.join("\n") if errors.any?
  raise MigrationAlreadyExists if AccountMigration.where(old_person: old_person).any?
end