Class: Textus::Maintenance::Migrate

Inherits:
Object
  • Object
show all
Extended by:
Contract::DSL
Defined in:
lib/textus/maintenance/migrate.rb

Overview

Loads a YAML migration plan and dispatches each op to the appropriate Maintenance use case. Concatenates resulting Plans.

Instance Method Summary collapse

Methods included from Contract::DSL

arg, contract, contract?, response, summary, surfaces, verb

Constructor Details

#initialize(container:, call:) ⇒ Migrate

Returns a new instance of Migrate.



17
18
19
20
# File 'lib/textus/maintenance/migrate.rb', line 17

def initialize(container:, call:)
  @container    = container
  @call         = call
end

Instance Method Details

#call(plan_yaml:, dry_run: false) ⇒ Object

Raises:



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/textus/maintenance/migrate.rb', line 22

def call(plan_yaml:, dry_run: false)
  raw = YAML.safe_load(plan_yaml, permitted_classes: [Symbol], aliases: false)
  raise UsageError.new("migration plan must be a YAML mapping") unless raw.is_a?(Hash)

  ops = Array(raw["operations"])
  all_steps = []
  warnings = []

  ops.each do |op_hash|
    op_name = op_hash["op"]
    sub_plan = invoke_op(op_name, op_hash, dry_run: dry_run)
    all_steps.concat(sub_plan.steps)
    warnings.concat(sub_plan.warnings)
  end

  Plan.new(steps: all_steps, warnings: warnings)
end