Class: ShopifyCli::ProjectType

Inherits:
Object
  • Object
show all
Extended by:
Feature::Set
Defined in:
lib/shopify-cli/project_type.rb

Class Attribute Summary collapse

Class Method Summary collapse

Methods included from Feature::Set

hidden?, hidden_feature

Class Attribute Details

.project_creator_command_classObject

Returns the value of attribute project_creator_command_class.



6
7
8
# File 'lib/shopify-cli/project_type.rb', line 6

def project_creator_command_class
  @project_creator_command_class
end

.project_load_shallowObject

Returns the value of attribute project_load_shallow.



6
7
8
# File 'lib/shopify-cli/project_type.rb', line 6

def project_load_shallow
  @project_load_shallow
end

.project_nameObject

Returns the value of attribute project_name.



6
7
8
# File 'lib/shopify-cli/project_type.rb', line 6

def project_name
  @project_name
end

.project_typeObject

Returns the value of attribute project_type.



6
7
8
# File 'lib/shopify-cli/project_type.rb', line 6

def project_type
  @project_type
end

Class Method Details

.create_commandObject



54
55
56
# File 'lib/shopify-cli/project_type.rb', line 54

def create_command
  const_get(@project_creator_command_class)
end

.creator(name, command_const) ⇒ Object



48
49
50
51
52
# File 'lib/shopify-cli/project_type.rb', line 48

def creator(name, command_const)
  @project_name = name
  @project_creator_command_class = command_const
  ShopifyCli::Commands::Create.subcommand(command_const, @project_type)
end

.for_app_type(type) ⇒ Object



40
41
42
# File 'lib/shopify-cli/project_type.rb', line 40

def for_app_type(type)
  repository.find { |k| k.project_type.to_s == type.to_s }
end

.inherited(klass) ⇒ Object



16
17
18
19
20
21
# File 'lib/shopify-cli/project_type.rb', line 16

def inherited(klass)
  super
  repository << klass
  klass.project_type = @current_type
  klass.project_load_shallow = @shallow_load
end

.load_allObject



34
35
36
37
38
# File 'lib/shopify-cli/project_type.rb', line 34

def load_all
  Dir.glob(File.join(ShopifyCli::ROOT, 'lib', 'project_types', '*', 'cli.rb')).map do |filepath|
    load_type(filepath.split(File::Separator)[-2].to_sym, true)
  end
end

.load_type(current_type, shallow = false) ⇒ Object



23
24
25
26
27
28
29
30
31
32
# File 'lib/shopify-cli/project_type.rb', line 23

def load_type(current_type, shallow = false)
  filepath = File.join(ShopifyCli::ROOT, 'lib', 'project_types', current_type.to_s, 'cli.rb')
  return unless File.exist?(filepath)
  @shallow_load = shallow
  @current_type = current_type
  load(filepath)
  @current_type = nil
  @shallow_load = false
  for_app_type(current_type)
end

.project_filepath(path) ⇒ Object



44
45
46
# File 'lib/shopify-cli/project_type.rb', line 44

def project_filepath(path)
  File.join(ShopifyCli::PROJECT_TYPES_DIR, project_type.to_s, path)
end

.register_command(const, cmd) ⇒ Object



58
59
60
61
62
63
64
# File 'lib/shopify-cli/project_type.rb', line 58

def register_command(const, cmd)
  return if project_load_shallow
  Context.new.abort(
    Context.message('core.project_type.error.cannot_override_core', cmd, const)
  ) if Commands.core_command?(cmd)
  Commands.register(const, cmd)
end

.register_messages(messages) ⇒ Object



71
72
73
74
75
76
77
78
# File 'lib/shopify-cli/project_type.rb', line 71

def register_messages(messages)
  # Make sure we don't attempt to register a file more than once as that will fail
  @registered_message_files ||= {}
  return if @registered_message_files.key?(@project_type)
  @registered_message_files[@project_type] = true

  Context.load_messages(messages)
end

.register_task(task, name) ⇒ Object



66
67
68
69
# File 'lib/shopify-cli/project_type.rb', line 66

def register_task(task, name)
  return if project_load_shallow
  ShopifyCli::Task.register(task, name)
end

.repositoryObject Also known as: all_loaded



11
12
13
# File 'lib/shopify-cli/project_type.rb', line 11

def repository
  @repository ||= []
end