Module: Extension::Messages::MessageLoading

Defined in:
lib/project_types/extension/messages/message_loading.rb

Class Method Summary collapse

Class Method Details

.deep_merge(first, second) ⇒ Object



31
32
33
34
# File 'lib/project_types/extension/messages/message_loading.rb', line 31

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

.loadObject



6
7
8
9
10
11
12
13
14
15
# File 'lib/project_types/extension/messages/message_loading.rb', line 6

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

.load_current_type_messagesObject



17
18
19
20
# File 'lib/project_types/extension/messages/message_loading.rb', line 17

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

.messages_for_type(type_identifier) ⇒ Object



22
23
24
25
26
27
28
29
# File 'lib/project_types/extension/messages/message_loading.rb', line 22

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