Sha256: 5b2ea6b1af9bdddd65f22202a61d4be3956aad7a572716d7cfe39365f0aaae33

Contents?: true

Size: 1.68 KB

Versions: 45

Compression:

Stored size: 1.68 KB

Contents

# frozen_string_literal: true

module Extension
  module Forms
    module Questions
      class AskRegistration
        include ShopifyCLI::MethodObject

        property! :ctx
        property! :type
        property! :prompt,
          converts: :to_proc,
          default: -> { CLI::UI::Prompt.method(:ask) }

        def call(project_details)
          project_details.tap(&method(:prompt_for_registration))
        end

        private

        def prompt_for_registration(project_details)
          apps_and_registrations = load_registrations(type)
          app, registration = choose_interactively(apps_and_registrations)
          project_details.app = app
          project_details.registration = registration
        end

        def choose_interactively(apps_and_registrations)
          prompt.call(ctx.message("connect.ask_registration")) do |handler|
            apps_and_registrations.each do |(app, extension)|
              handler.option("#{app.title} by #{app.business_name}: #{extension.title}") { [app, extension] }
            end
          end
        end

        def load_registrations(type)
          registrations = []
          loading_extensions = @ctx.message("connect.loading_extensions")

          CLI::UI::Spinner.spin(loading_extensions) do |_spinner|
            registrations += Tasks::GetExtensions.call(context: ctx, type: type)
          end

          registrations.empty? ? abort_no_registrations : registrations
        end

        def abort_no_registrations
          ctx.puts(@ctx.message("connect.no_extensions", type))
          ctx.puts(@ctx.message("connect.learn_about_extensions"))
          raise ShopifyCLI::AbortSilent
        end
      end
    end
  end
end

Version data entries

45 entries across 45 versions & 1 rubygems

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