Class: Extension::Tasks::EnsureResourceUrl

Inherits:
ShopifyCLI::Task show all
Includes:
SmartProperties
Defined in:
lib/project_types/extension/tasks/ensure_resource_url.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.call(*args) ⇒ Object



12
13
14
# File 'lib/project_types/extension/tasks/ensure_resource_url.rb', line 12

def self.call(*args)
  new(*args).call
end

Instance Method Details

#callObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/project_types/extension/tasks/ensure_resource_url.rb', line 16

def call
  project = ExtensionProject.current(force_reload: true)

  ShopifyCLI::Result
    .wrap(project.resource_url)
    .rescue { specification_handler.build_resource_url(shop: project.env.shop, context: context) }
    .then(&method(:persist_resource_url))
    .unwrap do |nil_or_exception|
      case nil_or_exception
      when nil
        context.warn(context.message("warnings.resource_url_auto_generation_failed", project.env.shop))
      else
        context.abort(nil_or_exception)
      end
    end
end

#persist_resource_url(resource_url) ⇒ Object



33
34
35
36
# File 'lib/project_types/extension/tasks/ensure_resource_url.rb', line 33

def persist_resource_url(resource_url)
  ExtensionProject.update_env_file(context: context, resource_url: resource_url)
  resource_url
end