Sha256: ab13b933578f7781e45f69d17cb667e32e4dbded3822da21480d1a94a3faa60c

Contents?: true

Size: 1.06 KB

Versions: 2

Compression:

Stored size: 1.06 KB

Contents

class Vendorer
  def initialize(options)
    @options = options
    eval(File.read('Vendorfile'))
  end

  private

  def file(options)
    options.each do |file, url|
      update_or_not file do
        run "mkdir -p #{File.dirname(file)}"
        run "curl '#{url}' -o #{file}"
        raise "Downloaded empty file" unless File.exist?(file)
      end
    end
  end

  def folder(options)
    options.each do |path, url|
      update_or_not path do
        run "mkdir -p #{File.dirname(path)}"
        run "git clone '#{url}' #{path}"
        run "rm -rf #{path}/.git"
      end
    end
  end

  def update_or_not(path)
    update_requested = (@options[:update] and (@options[:update] == true or @options[:update] == path))
    if update_requested or not File.exist?(path)
      puts "updating #{path}"
      run "rm -rf #{path}"
      yield
    else
      puts "keeping #{path}"
    end
  end

  def run(cmd)
    output = ''
    IO.popen(cmd + ' 2>&1') do |pipe|
      while line = pipe.gets
        output << line
      end
    end
    raise output unless $?.success?
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
vendorer-0.1.1 lib/vendorer.rb
vendorer-0.1.0 lib/vendorer.rb