Class: ShopifyCLI::Theme::DevelopmentTheme

Inherits:
Theme
  • Object
show all
Defined in:
lib/shopify_cli/theme/development_theme.rb

Direct Known Subclasses

Extension::HostTheme

Instance Attribute Summary

Attributes inherited from Theme

#root

Attributes inherited from Root

#ctx, #root

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Theme

all, #create, create_unpublished, #created_at_runtime?, #current_development?, #development?, #editor_url, find_by_identifier, #foreign_development?, #initialize, live, #live?, #preview_url, #publish, #shop, #theme_file?, #theme_files, #to_h

Methods inherited from Root

#[], #file?, #glob, #initialize, #json_files, #liquid_files, #static_asset_file?, #static_asset_files, #static_asset_paths

Constructor Details

This class inherits a constructor from ShopifyCLI::Theme::Theme

Class Method Details

.delete(ctx) ⇒ Object



61
62
63
# File 'lib/shopify_cli/theme/development_theme.rb', line 61

def self.delete(ctx)
  new(ctx).delete
end

.find(ctx, root: nil) ⇒ Object



65
66
67
68
# File 'lib/shopify_cli/theme/development_theme.rb', line 65

def self.find(ctx, root: nil)
  dev_theme = new(ctx, root: root)
  dev_theme.exists? ? dev_theme : nil
end

.find_or_create!(ctx, root: nil) ⇒ Object



70
71
72
# File 'lib/shopify_cli/theme/development_theme.rb', line 70

def self.find_or_create!(ctx, root: nil)
  new(ctx, root: root).ensure_exists!
end

Instance Method Details

#deleteObject



55
56
57
58
59
# File 'lib/shopify_cli/theme/development_theme.rb', line 55

def delete
  super if exists?
  ShopifyCLI::DB.del(:development_theme_id) if ShopifyCLI::DB.exists?(:development_theme_id)
  ShopifyCLI::DB.del(:development_theme_name) if ShopifyCLI::DB.exists?(:development_theme_name)
end

#ensure_exists!Object



33
34
35
36
37
38
39
40
41
42
43
# File 'lib/shopify_cli/theme/development_theme.rb', line 33

def ensure_exists!
  if exists?
    @ctx.debug("Using temporary development theme: ##{id} #{name}")
  else
    create
    @ctx.debug("Created temporary development theme: #{@id}")
    ShopifyCLI::DB.set(development_theme_id: @id)
  end

  self
end

#exists?Boolean

Returns:

  • (Boolean)


45
46
47
48
49
50
51
52
53
# File 'lib/shopify_cli/theme/development_theme.rb', line 45

def exists?
  return false unless id

  api_client.get(
    path: "themes/#{id}.json"
  )
rescue ShopifyCLI::API::APIRequestNotFoundError
  false
end

#idObject



12
13
14
# File 'lib/shopify_cli/theme/development_theme.rb', line 12

def id
  ShopifyCLI::DB.get(:development_theme_id)
end

#nameObject



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/shopify_cli/theme/development_theme.rb', line 16

def name
  existing_name = ShopifyCLI::DB.get(:development_theme_name)
  # Up to version 2.3.0 (included) generated names stored locally
  # could have more than 50 characters and the API rejected them.
  # This code ensures we update the name for those users to ensure
  # the name stays under the limit.
  if existing_name.nil? || existing_name.length > API_NAME_LIMIT
    generate_theme_name
  else
    existing_name
  end
end

#roleObject



29
30
31
# File 'lib/shopify_cli/theme/development_theme.rb', line 29

def role
  "development"
end