Class: Textus::Maintenance::Migrate

Inherits:
Object
  • Object
show all
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

Constructor Details

#initialize(container:, call:) ⇒ Migrate

Returns a new instance of Migrate.



8
9
10
11
# File 'lib/textus/maintenance/migrate.rb', line 8

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

Instance Method Details

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

Raises:



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/textus/maintenance/migrate.rb', line 13

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