Class: Textus::Maintenance::ZoneMv
- Inherits:
-
Object
- Object
- Textus::Maintenance::ZoneMv
- Defined in:
- lib/textus/maintenance/zone_mv.rb
Overview
Rename a zone — rewrites the manifest’s zones[] entry, rewrites the ‘zone:` field on every entry under the old zone, and moves every file from zones/<old>/ to zones/<new>/.
Instance Method Summary collapse
- #call(from:, to:, dry_run: false) ⇒ Object
-
#initialize(container:, call:) ⇒ ZoneMv
constructor
A new instance of ZoneMv.
Constructor Details
#initialize(container:, call:) ⇒ ZoneMv
Returns a new instance of ZoneMv.
9 10 11 12 13 14 |
# File 'lib/textus/maintenance/zone_mv.rb', line 9 def initialize(container:, call:) @container = container @call = call @manifest = container.manifest @root = container.root end |
Instance Method Details
#call(from:, to:, dry_run: false) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/textus/maintenance/zone_mv.rb', line 16 def call(from:, to:, dry_run: false) raise UsageError.new("from and to required") if from.nil? || to.nil? || from.empty? || to.empty? raise UsageError.new("zone '#{from}' not declared") unless @manifest.data.zones.key?(from) dest_dir = File.join(@root, "zones", to) raise UsageError.new("destination 'zones/#{to}' already exists") if File.exist?(dest_dir) affected_keys = @manifest.data.entries.select { |e| e.zone == from }.map(&:key) steps = [{ "op" => "rename_zone", "from" => from, "to" => to }] steps += affected_keys.map { |k| { "op" => "mv", "from" => k, "to" => "#{to}#{k[from.length..]}" } } plan = Plan.new(steps: steps, warnings: []) return plan if dry_run rewrite_manifest!(from, to) FileUtils.mv(File.join(@root, "zones", from), dest_dir) plan end |