Sha256: ecdebab9e59ae97a8046aeda8620f17d0960217e1567ffc69a7758bfa089ff70

Contents?: true

Size: 1.12 KB

Versions: 11

Compression:

Stored size: 1.12 KB

Contents

require 'dply/helper'
require 'fileutils'
module Dply
  class ConfigDownloader

    include Helper
    attr_writer :skip_download

    def initialize(config_files , base_url)
      @config_files = config_files
      @base_url = base_url
      @skip_download = []
    end

    def download_all
      init_tmpdir
      @config_files.each do |f|
        if @skip_download.include? f
          logger.debug "skipping to download file #{f}"
          next
        end
        download f
        FileUtils.mv "#{tmpdir}/#{f}", "config/#{f}"
      end
    end

    private

    def download(file)
      url = "#{@base_url}/#{file}"
      logger.bullet "downloading #{file}"
      http_status = `curl -w "%{http_code}" -f -s -o '#{tmpdir}/#{file}' '#{url}' `
      exitstatus = $?.exitstatus
      if (http_status != "200"  || exitstatus != 0 )
        error "failed to download #{file}, http status #{http_status}, exitstatus #{exitstatus}"
      end
    end

    def tmpdir
      @tmpdir ||= "tmp/config_dl"
    end

    def init_tmpdir
      if File.exists? tmpdir
        FileUtils.rm_rf tmpdir
      end
      FileUtils.mkdir_p tmpdir
    end

  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
dply-0.2.3 lib/dply/config_downloader.rb
dply-0.2.2 lib/dply/config_downloader.rb
dply-0.2.0 lib/dply/config_downloader.rb
dply-0.1.19 lib/dply/config_downloader.rb
dply-0.1.18 lib/dply/config_downloader.rb
dply-0.1.17 lib/dply/config_downloader.rb
dply-0.1.13 lib/dply/config_downloader.rb
dply-0.1.12 lib/dply/config_downloader.rb
dply-0.1.11 lib/dply/config_downloader.rb
dply-0.1.10 lib/dply/config_downloader.rb
dply-0.1.9 lib/dply/config_downloader.rb