Sha256: a38ca75ef609172255822025f8893b845949eb08fb9d385b861db4253550189a

Contents?: true

Size: 1.38 KB

Versions: 2

Compression:

Stored size: 1.38 KB

Contents

require 'uri'
require 'pathname'
require 'chrysalis/repository'
require 'chrysalis/ar'


module Chrysalis
module VCS
module File

  # Implements support for copying dependencies from a file system.
  #
  # Repositories of this type are identified by <em>file://</em> URLs.
  #
  # Example:
  #  - file:///Users/jaredhanson/Projects/libfoo
  
  class Repository < Chrysalis::Repository
    
    def self.retrieves?(url, params = {})
      uri = URI::parse(url)
      return uri.scheme == 'file'
    end
    
    
    def initialize(url, params = {})
      @url = url
      @params = params
    end
    
    def retrieve(to = '.')
      target = Pathname.new(to).join(copy_to)
      raise IOError, "Refusing to overwrite existing path. (path: #{target})" if target.exist?
    
      unless @params[:noop]
        puts ""
        puts "Copying #{@url} ..."
      
        source = URI::parse(@url)
        FileUtils.cp_r(source.path, target)
      end
      
      extract_path = Archive.extract(target.to_s, to, @params)
      WorkingCopy.new(:url => @url,
                      :path => extract_path)
    end
    
    private
      def copy_to
        return @params[:copy_to] if @params[:copy_to]
        
        uri = URI::parse(@url)
        dir = uri.path.split('/')[-1]
        
        raise ParameterError, "Invalid URL. (URL: #{@url})" if dir.nil?
        return dir
      end
    
  end

end
end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
chrysalis-0.1.0 lib/chrysalis/vcs/file/repository.rb
chrysalis-0.1.1 lib/chrysalis/vcs/file/repository.rb