Sha256: 3eda56dc0a6659f2fb44c5788bca1d1b8f69249214e1e1ba70722d26ba1f688d

Contents?: true

Size: 921 Bytes

Versions: 1

Compression:

Stored size: 921 Bytes

Contents

require 'pathname'
require 'open-uri'

module Menagerie
  ##
  # Artifacts are a stored file for a particular version of a project
  class Artifact
    attr_reader :version, :name, :base, :path

    def initialize(params = {})
      @config = params
      @path = @config[:path] || create
      @base, @name = Pathname.new(path).split.map(&:to_s)
      @version = File.basename File.readlink(path)
    end

    def create
      name, version, url = @config[:artifact].values_at :name, :version, :url
      path = "#{@config[:paths][:artifacts]}/#{name}/#{version}"
      download url, path unless File.exist? path
      File.chmod(@config[:artifact][:mode], path) if @config[:artifact][:mode]
      path
    end

    private

    def download(url, path)
      FileUtils.mkdir_p File.dirname(path)
      File.open(path, 'wb') do |fh|
        open(url, 'rb') { |request| fh.write request.read }
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
menagerie-0.0.1 lib/menagerie/artifact.rb