Class: PlatformosCheck::PlatformosLiquid::SourceManager

Inherits:
Object
  • Object
show all
Defined in:
lib/platformos_check/platformos_liquid/source_manager.rb

Defined Under Namespace

Classes: DownloadResourceError

Constant Summary collapse

REQUIRED_FILE_NAMES =
%i[filters objects tags latest].freeze

Class Method Summary collapse

Class Method Details

.download(destination = default_destination) ⇒ Object



23
24
25
26
27
28
29
30
31
32
# File 'lib/platformos_check/platformos_liquid/source_manager.rb', line 23

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
rescue DownloadResourceError
  # If a request error occurs, ignore it. This ensures that PlatformOS Check
  # can rely on the sources included during the bundling phase.
end

.download_or_refresh_files(destination = default_destination) ⇒ Object



15
16
17
18
19
20
21
# File 'lib/platformos_check/platformos_liquid/source_manager.rb', line 15

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

Returns:

  • (Boolean)


42
43
44
# File 'lib/platformos_check/platformos_liquid/source_manager.rb', line 42

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



38
39
40
# File 'lib/platformos_check/platformos_liquid/source_manager.rb', line 38

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

.refresh(destination = default_destination) ⇒ Object



34
35
36
# File 'lib/platformos_check/platformos_liquid/source_manager.rb', line 34

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

.wait_downloadsObject



46
47
48
# File 'lib/platformos_check/platformos_liquid/source_manager.rb', line 46

def wait_downloads
  refresh_threads.each(&:join)
end