Sha256: 1a7106dc3b17a4b2fb7031da411a3a8c7a5d281b438b22ab4af7a911d4157c8e

Contents?: true

Size: 1.14 KB

Versions: 49

Compression:

Stored size: 1.14 KB

Contents

# frozen_string_literal: true
require "shopify_cli"

module Extension
  module Tasks
    class EnsureResourceUrl < ShopifyCLI::Task
      include SmartProperties

      property! :context, accepts: ShopifyCLI::Context
      property! :specification_handler, accepts: Extension::Models::SpecificationHandlers::Default

      def self.call(*args)
        new(*args).call
      end

      def call
        project = ExtensionProject.current(force_reload: true)

        ShopifyCLI::Result
          .wrap(project.resource_url)
          .rescue { specification_handler.build_resource_url(shop: project.env.shop, context: context) }
          .then(&method(:persist_resource_url))
          .unwrap do |nil_or_exception|
            case nil_or_exception
            when nil
              context.warn(context.message("warnings.resource_url_auto_generation_failed", project.env.shop))
            else
              context.abort(nil_or_exception)
            end
          end
      end

      def persist_resource_url(resource_url)
        ExtensionProject.update_env_file(context: context, resource_url: resource_url)
        resource_url
      end
    end
  end
end

Version data entries

49 entries across 49 versions & 1 rubygems

Version Path
shopify-cli-2.36.0 lib/project_types/extension/tasks/ensure_resource_url.rb
shopify-cli-2.35.0 lib/project_types/extension/tasks/ensure_resource_url.rb
shopify-cli-2.34.0 lib/project_types/extension/tasks/ensure_resource_url.rb
shopify-cli-2.33.1 lib/project_types/extension/tasks/ensure_resource_url.rb
shopify-cli-2.33.0 lib/project_types/extension/tasks/ensure_resource_url.rb
shopify-cli-2.32.1 lib/project_types/extension/tasks/ensure_resource_url.rb
shopify-cli-2.32.0 lib/project_types/extension/tasks/ensure_resource_url.rb
shopify-cli-2.31.0 lib/project_types/extension/tasks/ensure_resource_url.rb
shopify-cli-2.30.0 lib/project_types/extension/tasks/ensure_resource_url.rb
shopify-cli-2.29.0 lib/project_types/extension/tasks/ensure_resource_url.rb
shopify-cli-2.28.0 lib/project_types/extension/tasks/ensure_resource_url.rb
shopify-cli-2.27.0 lib/project_types/extension/tasks/ensure_resource_url.rb
shopify-cli-2.26.0 lib/project_types/extension/tasks/ensure_resource_url.rb
shopify-cli-2.25.0 lib/project_types/extension/tasks/ensure_resource_url.rb
shopify-cli-2.24.0 lib/project_types/extension/tasks/ensure_resource_url.rb
shopify-cli-2.23.0 lib/project_types/extension/tasks/ensure_resource_url.rb
shopify-cli-2.22.0 lib/project_types/extension/tasks/ensure_resource_url.rb
shopify-cli-2.21.0 lib/project_types/extension/tasks/ensure_resource_url.rb
shopify-cli-2.20.1 lib/project_types/extension/tasks/ensure_resource_url.rb
shopify-cli-2.20.0 lib/project_types/extension/tasks/ensure_resource_url.rb