Class: Gel::Catalog
- Inherits:
-
Object
show all
- Defined in:
- lib/gel/catalog.rb
Defined Under Namespace
Modules: Common
Classes: CompactIndex, DependencyIndex, LegacyIndex
Constant Summary
collapse
- UPDATE_CONCURRENCY =
8
- VARIANT_GEMS =
%w(libv8)
Instance Method Summary
collapse
Constructor Details
#initialize(uri, httpool: Gel::Httpool.new, work_pool:, cache: ENV["GEL_CACHE"] || "~/.cache/gel", initial_gems: []) ⇒ Catalog
14
15
16
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/gel/catalog.rb', line 14
def initialize(uri, httpool: Gel::Httpool.new, work_pool:, cache: ENV["GEL_CACHE"] || "~/.cache/gel", initial_gems: [])
@uri = normalize_uri(uri)
@httpool = httpool
@work_pool = work_pool
@cache = cache
@initial_gems = initial_gems
@indexes = [
:compact_index,
:dependency_index,
:legacy_index,
]
end
|
Instance Method Details
#cached_gem(name, version) ⇒ Object
66
67
68
69
|
# File 'lib/gel/catalog.rb', line 66
def cached_gem(name, version)
path = cache_path(name, version)
return path if File.exist?(path)
end
|
#compact_index ⇒ Object
39
40
41
|
# File 'lib/gel/catalog.rb', line 39
def compact_index
@compact_index ||= Gel::Catalog::CompactIndex.new(@uri, uri_identifier, httpool: @httpool, work_pool: @work_pool, cache: @cache)
end
|
#dependency_index ⇒ Object
43
44
45
|
# File 'lib/gel/catalog.rb', line 43
def dependency_index
@dependency_index ||= Gel::Catalog::DependencyIndex.new(self, @uri, uri_identifier, httpool: @httpool, work_pool: @work_pool, cache: @cache)
end
|
#download_gem(name, version) ⇒ Object
71
72
73
74
75
76
77
78
79
80
81
82
83
|
# File 'lib/gel/catalog.rb', line 71
def download_gem(name, version)
path = cache_path(name, version)
return path if File.exist?(path)
name, version = guess_version(name, version)
response = http_get("/gems/#{name}-#{version}.gem")
FileUtils.mkdir_p(cache_dir) unless Dir.exist?(cache_dir)
File.open(path, "wb") do |f|
f.write(response.body)
end
path
end
|
#gem_info(name) ⇒ Object
55
56
57
58
59
60
61
62
63
64
|
# File 'lib/gel/catalog.rb', line 55
def gem_info(name)
index.gem_info(name)
rescue Net::HTTPExceptions
if @indexes.size > 1
@indexes.shift
retry
else
raise
end
end
|
#guess_version(name, version) ⇒ Object
86
87
88
89
90
91
92
|
# File 'lib/gel/catalog.rb', line 86
def guess_version(name, version)
if VARIANT_GEMS.include?(name)
[name, "#{version}-#{platform_specific_version}"]
else
[name, version]
end
end
|
#index ⇒ Object
51
52
53
|
# File 'lib/gel/catalog.rb', line 51
def index
send(@indexes.first)
end
|
#inspect ⇒ Object
98
99
100
|
# File 'lib/gel/catalog.rb', line 98
def inspect
"#<#{self.class} #{to_s.inspect}>"
end
|
#legacy_index ⇒ Object
47
48
49
|
# File 'lib/gel/catalog.rb', line 47
def legacy_index
@legacy_index ||= Gel::Catalog::LegacyIndex.new(@uri, uri_identifier, httpool: @httpool, work_pool: @work_pool, cache: @cache)
end
|
94
95
96
|
# File 'lib/gel/catalog.rb', line 94
def platform_specific_version
Gel::Support::GemPlatform.new(RbConfig::CONFIG["arch"])
end
|
#prepare ⇒ Object
28
29
30
31
32
33
34
35
36
37
|
# File 'lib/gel/catalog.rb', line 28
def prepare
index.prepare(@initial_gems)
rescue Net::HTTPExceptions
if @indexes.size > 1
@indexes.shift
retry
else
raise
end
end
|
#to_s ⇒ Object
102
103
104
|
# File 'lib/gel/catalog.rb', line 102
def to_s
@uri.to_s
end
|