Sha256: de116ddb7114983e2532a6210aa47f546501b04a18c0ca99cbec61f8deab0f89

Contents?: true

Size: 1.09 KB

Versions: 2

Compression:

Stored size: 1.09 KB

Contents

require 'net/http'

module Assetify
  class Asset
    attr_accessor :type, :name, :url

    def initialize(type, name, url, ver = nil, params={})
      raise "NoType" unless type
      raise "NoName" unless name
      raise "NoURL" unless url
      @type, @name = type, name
      @ver = ver
      @url = @ver ? url.gsub(/{VERSION}/, @ver) : url
      @new_name = params[:name]
      @version  = params[:version]
    end

    def filename
      fname = Opt[:newname] ? name : url.split("/").last
      fname += ".#{type}" unless fname =~ /\.#{type}$/
    end

    def fullpath
      path = Opt["#{type}path".to_sym]
      File.join(path, filename) #Dir.pwd,
    end

    def check?
      File.exists? fullpath
    end

    def install!(force = false)
      print "Installing #{name}..."
      return puts "Installed" if !force && check?
      unless @data
        uri = URI.parse url
        Net::HTTP.start(uri.host) do |http|
          @data = http.get(uri.path)
        end
      end
      #puts "Writing to #{fullpath}"
      File.open(fullpath, "w") { |f| f.puts(@data) }
      puts "DONE"
    end

  end



end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
assetify-0.0.2 lib/assetify/asset.rb
assetify-0.0.1 lib/assetify/asset.rb