Class: Extension::Models::SpecificationHandlers::Default

Inherits:
Object
  • Object
show all
Defined in:
lib/project_types/extension/models/specification_handlers/default.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(specification) ⇒ Default

Returns a new instance of Default.



9
10
11
# File 'lib/project_types/extension/models/specification_handlers/default.rb', line 9

def initialize(specification)
  @specification = specification
end

Instance Attribute Details

#specificationObject (readonly)

Returns the value of attribute specification.



7
8
9
# File 'lib/project_types/extension/models/specification_handlers/default.rb', line 7

def specification
  @specification
end

Instance Method Details

#argo_runtime(context) ⇒ Object



75
76
77
78
79
80
81
82
# File 'lib/project_types/extension/models/specification_handlers/default.rb', line 75

def argo_runtime(context)
  return if supports_development_server?

  @argo_runtime ||= Features::ArgoRuntime.find(
    cli_package: cli_package(context),
    identifier: identifier
  )
end

#build_resource_url(shop) ⇒ Object

Raises:

  • (NotImplementedError)


107
108
109
# File 'lib/project_types/extension/models/specification_handlers/default.rb', line 107

def build_resource_url(shop)
  raise NotImplementedError
end

#choose_port?(context) ⇒ Boolean

Returns:

  • (Boolean)


45
46
47
48
# File 'lib/project_types/extension/models/specification_handlers/default.rb', line 45

def choose_port?(context)
  return true if supports_development_server?
  argo_runtime(context).supports?(:port)
end

#cli_package(context) ⇒ Object



84
85
86
87
88
89
90
91
# File 'lib/project_types/extension/models/specification_handlers/default.rb', line 84

def cli_package(context)
  cli_package_name = specification.features.argo&.cli_package_name
  return unless cli_package_name

  js_system = ShopifyCLI::JsSystem.new(ctx: context)
  Tasks::FindNpmPackages.exactly_one_of(cli_package_name, js_system: js_system)
    .unwrap { |_e| context.abort(context.message("errors.package_not_found", cli_package_name)) }
end

#config(context) ⇒ Object



29
30
31
# File 'lib/project_types/extension/models/specification_handlers/default.rb', line 29

def config(context)
  argo.config(context)
end

#create(directory_name, context, **_args) ⇒ Object



33
34
35
# File 'lib/project_types/extension/models/specification_handlers/default.rb', line 33

def create(directory_name, context, **_args)
  argo.create(directory_name, identifier, context)
end

#establish_tunnel?(context) ⇒ Boolean

Returns:

  • (Boolean)


50
51
52
53
# File 'lib/project_types/extension/models/specification_handlers/default.rb', line 50

def establish_tunnel?(context)
  return true if supports_development_server?
  argo_runtime(context).supports?(:public_url)
end

#extension_context(_context) ⇒ Object



37
38
39
# File 'lib/project_types/extension/models/specification_handlers/default.rb', line 37

def extension_context(_context)
  nil
end

#graphql_identifierObject



17
18
19
# File 'lib/project_types/extension/models/specification_handlers/default.rb', line 17

def graphql_identifier
  specification.graphql_identifier.to_s.upcase
end

#identifierObject



13
14
15
# File 'lib/project_types/extension/models/specification_handlers/default.rb', line 13

def identifier
  specification.identifier.to_s.upcase
end

#message_for_extension(key, *params) ⇒ Object



93
94
95
96
97
98
99
100
101
# File 'lib/project_types/extension/models/specification_handlers/default.rb', line 93

def message_for_extension(key, *params)
  override_key = "overrides.#{key}"
  key_parts = override_key.split(".").map(&:to_sym)
  if (str = messages.dig(*key_parts))
    str % params
  else
    ShopifyCLI::Context.message(key, *params)
  end
end

#nameObject



21
22
23
# File 'lib/project_types/extension/models/specification_handlers/default.rb', line 21

def name
  message("name") || specification.name
end

#renderer_package(context) ⇒ Object



71
72
73
# File 'lib/project_types/extension/models/specification_handlers/default.rb', line 71

def renderer_package(context)
  argo.renderer_package(context)
end

#serve(**options) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/project_types/extension/models/specification_handlers/default.rb', line 55

def serve(**options)
  context = options[:context]
  port = options[:port]
  tunnel_url = options[:tunnel_url]
  resource_url = options[:resource_url]

  Features::ArgoServe.new(
    specification_handler: self,
    argo_runtime: argo_runtime(context),
    context: context,
    port: port,
    tunnel_url: tunnel_url,
    resource_url: resource_url
  ).call
end

#server_config_fileObject



115
116
117
# File 'lib/project_types/extension/models/specification_handlers/default.rb', line 115

def server_config_file
  "extension.config.yml"
end

#server_config_path(base_dir = Dir.pwd) ⇒ Object



111
112
113
# File 'lib/project_types/extension/models/specification_handlers/default.rb', line 111

def server_config_path(base_dir = Dir.pwd)
  File.join(base_dir, server_config_file)
end

#supplies_resource_url?Boolean

Returns:

  • (Boolean)


103
104
105
# File 'lib/project_types/extension/models/specification_handlers/default.rb', line 103

def supplies_resource_url?
  false
end

#taglineObject



25
26
27
# File 'lib/project_types/extension/models/specification_handlers/default.rb', line 25

def tagline
  message("tagline") || ""
end

#valid_extension_contextsObject



41
42
43
# File 'lib/project_types/extension/models/specification_handlers/default.rb', line 41

def valid_extension_contexts
  []
end