1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
|
require 'uri'
require 'librarian/puppet/util'
require 'librarian/puppet/source/githubtarball/repo'
module Librarian
module Puppet
module Source
class GitHubTarball
include Librarian::Puppet::Util
class << self
LOCK_NAME = 'GITHUBTARBALL'
def lock_name
LOCK_NAME
end
def from_lock_options(environment, options)
new(environment, options[:remote], options.reject { |k, v| k == :remote })
end
def from_spec_args(environment, uri, options)
recognised_options = []
unrecognised_options = options.keys - recognised_options
unless unrecognised_options.empty?
raise Error, "unrecognised options: #{unrecognised_options.join(", ")}"
end
new(environment, uri, options)
end
end
attr_accessor :environment
private :environment=
attr_reader :uri
def initialize(environment, uri, options = {})
self.environment = environment
@uri = URI::parse(uri)
@cache_path = nil
end
def to_s
clean_uri(uri).to_s
end
def ==(other)
other &&
self.class == other.class &&
self.uri == other.uri
end
alias :eql? :==
def hash
self.to_s.hash
end
def to_spec_args
[clean_uri(uri).to_s, {}]
end
def to_lock_options
{:remote => clean_uri(uri).to_s}
end
def pinned?
false
end
def unpin!
end
def install!(manifest)
manifest.source == self or raise ArgumentError
debug { "Installing #{manifest}" }
name = manifest.name
version = manifest.version
install_path = install_path(name)
repo = repo(name)
repo.install_version! version, install_path
end
def manifest(name, version, dependencies)
manifest = Manifest.new(self, name)
manifest.version = version
manifest.dependencies = dependencies
manifest
end
def cache_path
@cache_path ||= begin
environment.cache_path.join("source/puppet/githubtarball/#{uri.host}#{uri.path}")
end
end
def install_path(name)
environment.install_path.join(module_name(name))
end
def fetch_version(name, version_uri)
versions = repo(name).versions
if versions.include? version_uri
version_uri
else
versions.first
end
end
def fetch_dependencies(name, version, version_uri)
{}
end
def manifests(name)
repo(name).manifests
end
private
def repo(name)
@repo ||= {}
@repo[name] ||= Repo.new(self, name)
end
end
end
end
end
|