Class: Extension::ExtensionProject

Inherits:
ShopifyCli::Project show all
Defined in:
lib/project_types/extension/extension_project.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ShopifyCli::Project

#config, current, current_project_type, #env, has_current?, project_name, write

Class Method Details

.write_cli_file(context:, type:) ⇒ Object



7
8
9
10
11
12
13
14
# File 'lib/project_types/extension/extension_project.rb', line 7

def write_cli_file(context:, type:)
  ShopifyCli::Project.write(
    context,
    project_type: :extension,
    organization_id: nil,
    "#{ExtensionProjectKeys::EXTENSION_TYPE_KEY}": type
  )
end

.write_env_file(context:, title:, api_key: '', api_secret: '', registration_id: nil) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/project_types/extension/extension_project.rb', line 16

def write_env_file(context:, title:, api_key: '', api_secret: '', registration_id: nil)
  ShopifyCli::Resources::EnvFile.new(
    api_key: api_key,
    secret: api_secret,
    extra: {
      ExtensionProjectKeys::TITLE_KEY => title,
      ExtensionProjectKeys::REGISTRATION_ID_KEY => registration_id,
    }.compact
  ).write(context)

  current.reload unless project_empty?
end

Instance Method Details

#appObject



36
37
38
# File 'lib/project_types/extension/extension_project.rb', line 36

def app
  Models::App.new(api_key: env['api_key'], secret: env['secret'])
end

#extension_type_identifierObject



48
49
50
# File 'lib/project_types/extension/extension_project.rb', line 48

def extension_type_identifier
  config[ExtensionProjectKeys::EXTENSION_TYPE_KEY]
end

#registered?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/project_types/extension/extension_project.rb', line 40

def registered?
  property_present?('api_key') && property_present?('secret') && registration_id?
end

#registration_idObject



58
59
60
# File 'lib/project_types/extension/extension_project.rb', line 58

def registration_id
  get_extra_field(ExtensionProjectKeys::REGISTRATION_ID_KEY).to_i
end

#registration_id?Boolean

Returns:

  • (Boolean)


52
53
54
55
56
# File 'lib/project_types/extension/extension_project.rb', line 52

def registration_id?
  extra_property_present?(ExtensionProjectKeys::REGISTRATION_ID_KEY) &&
    integer?(get_extra_field(ExtensionProjectKeys::REGISTRATION_ID_KEY)) &&
    registration_id > 0
end

#reloadObject



62
63
64
# File 'lib/project_types/extension/extension_project.rb', line 62

def reload
  @env = nil
end

#titleObject



44
45
46
# File 'lib/project_types/extension/extension_project.rb', line 44

def title
  get_extra_field(ExtensionProjectKeys::TITLE_KEY)
end