Class: ThemeCheck::ShopifyLiquid::SourceManager

Inherits:
Object
  • Object
show all
Defined in:
lib/theme_check/shopify_liquid/source_manager.rb

Constant Summary collapse

REQUIRED_FILE_NAMES =
[:filters, :objects, :tags, :latest].freeze

Class Method Summary collapse

Class Method Details

.download(destination = default_destination) ⇒ Object



21
22
23
24
25
26
27
# File 'lib/theme_check/shopify_liquid/source_manager.rb', line 21

def download(destination = default_destination)
  Dir.mkdir(destination) unless destination.exist?

  REQUIRED_FILE_NAMES.each do |file_name|
    download_file(local_path(file_name, destination), remote_path(file_name))
  end
end

.download_or_refresh_files(destination = default_destination) ⇒ Object



13
14
15
16
17
18
19
# File 'lib/theme_check/shopify_liquid/source_manager.rb', line 13

def download_or_refresh_files(destination = default_destination)
  if has_required_files?(destination)
    refresh(destination)
  else
    download(destination)
  end
end

.has_required_files?(destination = default_destination) ⇒ Boolean



37
38
39
# File 'lib/theme_check/shopify_liquid/source_manager.rb', line 37

def has_required_files?(destination = default_destination)
  REQUIRED_FILE_NAMES.all? { |file_name| local_path(file_name, destination).exist? }
end

.local_path(file_name, destination = default_destination) ⇒ Object



33
34
35
# File 'lib/theme_check/shopify_liquid/source_manager.rb', line 33

def local_path(file_name, destination = default_destination)
  destination + "#{file_name}.json"
end

.refresh(destination = default_destination) ⇒ Object



29
30
31
# File 'lib/theme_check/shopify_liquid/source_manager.rb', line 29

def refresh(destination = default_destination)
  refresh_threads << Thread.new { refresh_thread(destination) }
end

.wait_downloadsObject



41
42
43
# File 'lib/theme_check/shopify_liquid/source_manager.rb', line 41

def wait_downloads
  refresh_threads.each(&:join)
end