Class: Textus::Action::DataMv
- Extended by:
- Contract::DSL
- Defined in:
- lib/textus/action/data_mv.rb
Constant Summary collapse
- BURN =
:sync
Instance Method Summary collapse
- #call(container:) ⇒ Object
-
#initialize(from:, to:, dry_run: false) ⇒ DataMv
constructor
A new instance of DataMv.
Methods included from Contract::DSL
arg, around, cli, cli_stdin, contract, contract?, summary, surfaces, verb, view
Methods inherited from Base
Constructor Details
#initialize(from:, to:, dry_run: false) ⇒ DataMv
Returns a new instance of DataMv.
24 25 26 27 28 29 |
# File 'lib/textus/action/data_mv.rb', line 24 def initialize(from:, to:, dry_run: false) super() @from = from @to = to @dry_run = dry_run end |
Instance Method Details
#call(container:) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/textus/action/data_mv.rb', line 31 def call(container:, **) manifest = container.manifest root = container.root raise UsageError.new("from and to required") if @from.nil? || @to.nil? || @from.empty? || @to.empty? raise UsageError.new("data lane '#{@from}' not declared") unless manifest.data.declared_lane_kinds.key?(@from) dest_dir = File.join(root, "data", @to) raise UsageError.new("destination 'data/#{@to}' already exists") if File.exist?(dest_dir) affected_keys = manifest.data.entries.select { |entry| entry.lane == @from }.map(&:key) steps = [{ "op" => "rename_zone", "from" => @from, "to" => @to }] steps += affected_keys.map do |key| { "op" => "mv", "from" => key, "to" => "#{@to}#{key[@from.length..]}" } end plan = Textus::Background::Plan.new(steps: steps, warnings: []) return plan if @dry_run rewrite_manifest!(root) FileUtils.mv(File.join(root, "data", @from), dest_dir) plan end |