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.19.0 lib/project_types/extension/tasks/ensure_resource_url.rb
shopify-cli-2.18.1 lib/project_types/extension/tasks/ensure_resource_url.rb
shopify-cli-2.18.0 lib/project_types/extension/tasks/ensure_resource_url.rb
shopify-cli-2.17.0 lib/project_types/extension/tasks/ensure_resource_url.rb
shopify-cli-2.16.1 lib/project_types/extension/tasks/ensure_resource_url.rb
shopify-cli-2.16.0 lib/project_types/extension/tasks/ensure_resource_url.rb
shopify-cli-2.15.6 lib/project_types/extension/tasks/ensure_resource_url.rb
shopify-cli-2.15.5 lib/project_types/extension/tasks/ensure_resource_url.rb
shopify-cli-2.15.4 lib/project_types/extension/tasks/ensure_resource_url.rb
shopify-cli-2.15.3 lib/project_types/extension/tasks/ensure_resource_url.rb
shopify-cli-2.15.2 lib/project_types/extension/tasks/ensure_resource_url.rb
shopify-cli-2.15.1 lib/project_types/extension/tasks/ensure_resource_url.rb
shopify-cli-2.15.0 lib/project_types/extension/tasks/ensure_resource_url.rb
shopify-cli-2.14.0 lib/project_types/extension/tasks/ensure_resource_url.rb
shopify-cli-2.13.0 lib/project_types/extension/tasks/ensure_resource_url.rb
shopify-cli-2.12.0 lib/project_types/extension/tasks/ensure_resource_url.rb
shopify-cli-2.11.2 lib/project_types/extension/tasks/ensure_resource_url.rb
shopify-cli-2.11.1 lib/project_types/extension/tasks/ensure_resource_url.rb
shopify-cli-2.11.0 lib/project_types/extension/tasks/ensure_resource_url.rb
shopify-cli-2.10.2 lib/project_types/extension/tasks/ensure_resource_url.rb