Sha256: 4ae7490d68425203b9273c5dd4352d381082ccf7de9d20c0b64c89ca50083f7c

Contents?: true

Size: 1.22 KB

Versions: 9

Compression:

Stored size: 1.22 KB

Contents

# frozen_string_literal: true

require_relative "forms/apply_to_all"
require_relative "forms/select_delete_strategy"

module ShopifyCLI
  module Theme
    class Syncer
      class Uploader
        module JsonDeleteHandler
          def enqueue_json_deletes(files)
            return enqueue_deletes(files) if overwrite_json?

            # Handle conflicts when JSON files cannot be overwritten
            handle_delete_conflicts(files)
          end

          private

          def handle_delete_conflicts(files)
            to_delete = []
            to_get = []

            apply_to_all = Forms::ApplyToAll.new(ctx, files.size)

            files.each do |file|
              delete_strategy = apply_to_all.value || ask_delete_strategy(file)
              apply_to_all.apply?(delete_strategy)

              case delete_strategy
              when :delete
                to_delete << file
              when :restore
                to_get << file
              end
            end

            enqueue_deletes(to_delete)
            enqueue_get(to_get)
          end

          def ask_delete_strategy(file)
            Forms::SelectDeleteStrategy.ask(ctx, [], file: file).strategy
          end
        end
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
shopify-cli-2.36.0 lib/shopify_cli/theme/syncer/uploader/json_delete_handler.rb
shopify-cli-2.35.0 lib/shopify_cli/theme/syncer/uploader/json_delete_handler.rb
shopify-cli-2.34.0 lib/shopify_cli/theme/syncer/uploader/json_delete_handler.rb
shopify-cli-2.33.1 lib/shopify_cli/theme/syncer/uploader/json_delete_handler.rb
shopify-cli-2.33.0 lib/shopify_cli/theme/syncer/uploader/json_delete_handler.rb
shopify-cli-2.32.1 lib/shopify_cli/theme/syncer/uploader/json_delete_handler.rb
shopify-cli-2.32.0 lib/shopify_cli/theme/syncer/uploader/json_delete_handler.rb
shopify-cli-2.31.0 lib/shopify_cli/theme/syncer/uploader/json_delete_handler.rb
shopify-cli-2.30.0 lib/shopify_cli/theme/syncer/uploader/json_delete_handler.rb