Class: RequestMigrations::Migrator

Inherits:
Object
  • Object
show all
Defined in:
lib/request_migrations/migrator.rb

Direct Known Subclasses

Controller::Migrator

Instance Method Summary collapse

Constructor Details

#initialize(from:, to:) ⇒ Migrator

Migrator represents a versioned migration from one version to another.

Parameters:

  • from (String, Integer, Float)

    the current version.

  • to (String, Integer, Float)

    the target version.



10
11
12
13
# File 'lib/request_migrations/migrator.rb', line 10

def initialize(from:, to:)
  @current_version = Version.new(from)
  @target_version  = Version.new(to)
end

Instance Method Details

#migrate!(data:) ⇒ void

This method returns an undefined value.

migrate! attempts to apply all matching migrations on data.

Parameters:

  • data (Any)

    the data to be migrated.



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/request_migrations/migrator.rb', line 21

def migrate!(data:)
  logger.debug { "Migrating from #{current_version} to #{target_version} (#{migrations.size} potential migrations)" }

  migrations.each_with_index { |migration, i|
    logger.debug { "Applying migration #{migration} (#{i + 1}/#{migrations.size})" }

    migration.new.migrate!(data)
  }

  logger.debug { "Migrated from #{current_version} to #{target_version}" }
end