Class: Kozo::Commands::State::Upgrade

Inherits:
Kozo::Commands::State show all
Defined in:
lib/kozo/commands/state/upgrade.rb

Instance Attribute Summary

Attributes inherited from Kozo::Commands::State

#subcommand

Attributes inherited from Kozo::Command

#args, #configuration

Instance Method Summary collapse

Constructor Details

#initialize(configuration, *_args) ⇒ Upgrade

Returns a new instance of Upgrade.



9
10
11
# File 'lib/kozo/commands/state/upgrade.rb', line 9

def initialize(configuration, *_args)
  @configuration = configuration
end

Instance Method Details

#startObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/kozo/commands/state/upgrade.rb', line 13

def start
  return Kozo.logger.info "State file already up to date." if state.compatible?

  ((state.version + 1)..Kozo::State::VERSION).each do |version|
    file = Dir[Kozo.root.join("lib/kozo/upgrade/#{version}_*")].first

    raise NotImplementedError, "upgrade file to version #{version} not found" unless file

    Kozo.logger.info "Upgrading state file to version #{version}"

    klass = File
      .basename(file, ".rb")
      .delete_prefix("#{version}_")
      .prepend("kozo/upgrade/")
      .camelize
      .constantize

    # Write state
    configuration.backend.state = klass
      .new(state)
      .upgrade
  end
end

#stateObject



37
38
39
40
41
# File 'lib/kozo/commands/state/upgrade.rb', line 37

def state
  @state ||= configuration
    .backend
    .state(verify: false)
end