Class: Textus::Maintenance::KeyMvPrefix
- Inherits:
-
Object
- Object
- Textus::Maintenance::KeyMvPrefix
- Defined in:
- lib/textus/maintenance/key_mv_prefix.rb
Overview
Bulk-rename every leaf key under ‘from_prefix` to `to_prefix`. Calls Write::Mv directly for each entry — emits one audit row per file moved.
Instance Method Summary collapse
- #call(from_prefix:, to_prefix:, dry_run: false) ⇒ Object
-
#initialize(container:, call:) ⇒ KeyMvPrefix
constructor
A new instance of KeyMvPrefix.
Constructor Details
#initialize(container:, call:) ⇒ KeyMvPrefix
Returns a new instance of KeyMvPrefix.
6 7 8 9 |
# File 'lib/textus/maintenance/key_mv_prefix.rb', line 6 def initialize(container:, call:) @container = container @call = call end |
Instance Method Details
#call(from_prefix:, to_prefix:, dry_run: false) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/textus/maintenance/key_mv_prefix.rb', line 11 def call(from_prefix:, to_prefix:, dry_run: false) raise UsageError.new("from_prefix and to_prefix required") if from_prefix.nil? || to_prefix.nil? leaves = list_leaves_under(from_prefix) warnings = [] warnings << "no keys under #{from_prefix}" if leaves.empty? steps = leaves.map do |old_key| tail = old_key.delete_prefix("#{from_prefix}.") new_key = "#{to_prefix}.#{tail}" { "op" => "mv", "from" => old_key, "to" => new_key } end plan = Plan.new(steps: steps, warnings: warnings) return plan if dry_run steps.each do |s| mv.call(s["from"], s["to"], dry_run: false) end plan end |