Sha256: ee20b7959d44d4259ead49cbb881bd4393882fc399882391baa494ffaed63956

Contents?: true

Size: 1.1 KB

Versions: 23

Compression:

Stored size: 1.1 KB

Contents

# frozen_string_literal: true

module Extension
  module Messages
    module MessageLoading
      def self.load
        type_specific_messages = load_current_type_messages
        return Messages::MESSAGES if type_specific_messages.nil?

        if type_specific_messages.key?(:overrides)
          deep_merge(Messages::MESSAGES, type_specific_messages[:overrides])
        else
          Messages::MESSAGES
        end
      end

      def self.load_current_type_messages
        return unless ShopifyCli::Project.has_current?
        messages_for_type(ShopifyCli::Project.current.config[Extension::ExtensionProjectKeys::EXTENSION_TYPE_KEY])
      end

      def self.messages_for_type(type_identifier)
        return if type_identifier.nil?

        type_identifier_symbol = type_identifier.downcase.to_sym
        return unless Messages::TYPES.key?(type_identifier_symbol)

        TYPES[type_identifier_symbol]
      end

      def self.deep_merge(first, second)
        merger = proc { |_key, v1, v2| Hash === v1 && Hash === v2 ? v1.merge(v2, &merger) : v2 }
        first.merge(second, &merger)
      end
    end
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
shopify-cli-1.8.0 lib/project_types/extension/messages/message_loading.rb
shopify-cli-1.7.1 lib/project_types/extension/messages/message_loading.rb
shopify-cli-1.7.0 lib/project_types/extension/messages/message_loading.rb
shopify-cli-1.6.0 lib/project_types/extension/messages/message_loading.rb
shopify-cli-1.5.0 lib/project_types/extension/messages/message_loading.rb
shopify-cli-1.4.1 lib/project_types/extension/messages/message_loading.rb
shopify-cli-1.4.0 lib/project_types/extension/messages/message_loading.rb
shopify-cli-1.3.1 lib/project_types/extension/messages/message_loading.rb
shopify-cli-1.3.0 lib/project_types/extension/messages/message_loading.rb
shopify-cli-1.2.0 lib/project_types/extension/messages/message_loading.rb
shopify-cli-1.1.2 lib/project_types/extension/messages/message_loading.rb
shopify-cli-1.1.1 lib/project_types/extension/messages/message_loading.rb
shopify-cli-1.1.0 lib/project_types/extension/messages/message_loading.rb
shopify-cli-1.0.5 lib/project_types/extension/messages/message_loading.rb
shopify-cli-1.0.4 lib/project_types/extension/messages/message_loading.rb
shopify-cli-1.0.3 lib/project_types/extension/messages/message_loading.rb
shopify-cli-1.0.2 lib/project_types/extension/messages/message_loading.rb
shopify-cli-1.0.1 lib/project_types/extension/messages/message_loading.rb
shopify-cli-1.0.0 lib/project_types/extension/messages/message_loading.rb
shopify-cli-0.9.3 lib/project_types/extension/messages/message_loading.rb