Class: Librarian::Puppet::Source::Forge

Inherits:
Object
  • Object
show all
Includes:
Util
Defined in:
lib/librarian/puppet/source/forge.rb,
lib/librarian/puppet/source/forge/repo.rb,
lib/librarian/puppet/source/forge/repo_v1.rb,
lib/librarian/puppet/source/forge/repo_v3.rb

Defined Under Namespace

Classes: Repo, RepoV1, RepoV3

Constant Summary collapse

LOCK_NAME =
'FORGE'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Util

#clean_uri, #cp_r, #debug, #info, #module_name, #normalize_name, #rsync?, #warn

Constructor Details

#initialize(environment, uri, options = {}) ⇒ Forge

Returns a new instance of Forge.



46
47
48
49
50
51
# File 'lib/librarian/puppet/source/forge.rb', line 46

def initialize(environment, uri, options = {})
  self.environment = environment

  @uri = URI::parse(uri)
  @cache_path = nil
end

Instance Attribute Details

#environmentObject

Returns the value of attribute environment.



42
43
44
# File 'lib/librarian/puppet/source/forge.rb', line 42

def environment
  @environment
end

#uriObject (readonly)

Returns the value of attribute uri.



44
45
46
# File 'lib/librarian/puppet/source/forge.rb', line 44

def uri
  @uri
end

Class Method Details

.defaultObject



19
20
21
# File 'lib/librarian/puppet/source/forge.rb', line 19

def default
  @@default
end

.default=(source) ⇒ Object



15
16
17
# File 'lib/librarian/puppet/source/forge.rb', line 15

def default=(source)
  @@default = source
end

.from_lock_options(environment, options) ⇒ Object



27
28
29
# File 'lib/librarian/puppet/source/forge.rb', line 27

def from_lock_options(environment, options)
  new(environment, options[:remote], options.reject { |k, v| k == :remote })
end

.from_spec_args(environment, uri, options) ⇒ Object



31
32
33
34
35
36
37
38
39
# File 'lib/librarian/puppet/source/forge.rb', line 31

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

.lock_nameObject



23
24
25
# File 'lib/librarian/puppet/source/forge.rb', line 23

def lock_name
  LOCK_NAME
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?



57
58
59
60
61
# File 'lib/librarian/puppet/source/forge.rb', line 57

def ==(other)
  other &&
  self.class == other.class &&
  self.uri == other.uri
end

#cache_pathObject



104
105
106
107
108
109
# File 'lib/librarian/puppet/source/forge.rb', line 104

def cache_path
  @cache_path ||= begin
    dir = "#{uri.host}#{uri.path}".gsub(/[^0-9a-z\-_]/i, '_')
    environment.cache_path.join("source/puppet/forge/#{dir}")
  end
end

#fetch_dependencies(name, version, version_uri) ⇒ Object



124
125
126
127
128
129
# File 'lib/librarian/puppet/source/forge.rb', line 124

def fetch_dependencies(name, version, version_uri)
  repo(name).dependencies(version).map do |k, v|
    v = Librarian::Dependency::Requirement.new(v).to_gem_requirement
    Dependency.new(k, v, nil, name)
  end
end

#fetch_version(name, version_uri) ⇒ Object



115
116
117
118
119
120
121
122
# File 'lib/librarian/puppet/source/forge.rb', line 115

def fetch_version(name, version_uri)
  versions = repo(name).versions
  if versions.include? version_uri
    version_uri
  else
    versions.first
  end
end

#hashObject



65
66
67
# File 'lib/librarian/puppet/source/forge.rb', line 65

def hash
  self.to_s.hash
end

#install!(manifest) ⇒ Object



84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/librarian/puppet/source/forge.rb', line 84

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

#install_path(name) ⇒ Object



111
112
113
# File 'lib/librarian/puppet/source/forge.rb', line 111

def install_path(name)
  environment.install_path.join(module_name(name))
end

#manifest(name, version, dependencies) ⇒ Object



97
98
99
100
101
102
# File 'lib/librarian/puppet/source/forge.rb', line 97

def manifest(name, version, dependencies)
  manifest = Manifest.new(self, name)
  manifest.version = version
  manifest.dependencies = dependencies
  manifest
end

#manifests(name) ⇒ Object



131
132
133
# File 'lib/librarian/puppet/source/forge.rb', line 131

def manifests(name)
  repo(name).manifests
end

#pinned?Boolean

Returns:

  • (Boolean)


77
78
79
# File 'lib/librarian/puppet/source/forge.rb', line 77

def pinned?
  false
end

#to_lock_optionsObject



73
74
75
# File 'lib/librarian/puppet/source/forge.rb', line 73

def to_lock_options
  {:remote => uri.to_s}
end

#to_sObject



53
54
55
# File 'lib/librarian/puppet/source/forge.rb', line 53

def to_s
  clean_uri(uri).to_s
end

#to_spec_argsObject



69
70
71
# File 'lib/librarian/puppet/source/forge.rb', line 69

def to_spec_args
  [clean_uri(uri).to_s, {}]
end

#unpin!Object



81
82
# File 'lib/librarian/puppet/source/forge.rb', line 81

def unpin!
end