Class: RequestMigrations::Controller::Migrator

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

Instance Method Summary collapse

Constructor Details

#initialize(request:, response:, **kwargs) ⇒ Migrator

Returns a new instance of Migrator.



8
9
10
11
12
13
# File 'lib/request_migrations/controller.rb', line 8

def initialize(request:, response:, **kwargs)
  super(**kwargs)

  @request  = request
  @response = response
end

Instance Method Details

#migrate!Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/request_migrations/controller.rb', line 15

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

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

    migration.new.migrate_request!(request)
  }

  yield

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

    migration.new.migrate_response!(response)
  }

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