forked from librariesio/libraries.io
-
Notifications
You must be signed in to change notification settings - Fork 2
/
rubygems.rb
107 lines (92 loc) · 2.92 KB
/
rubygems.rb
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
module PackageManager
class Rubygems < Base
HAS_VERSIONS = true
HAS_DEPENDENCIES = true
HAS_OWNERS = true
BIBLIOTHECARY_SUPPORT = true
SECURITY_PLANNED = true
URL = 'https://rubygems.org'
COLOR = '#701516'
def self.package_link(project, version = nil)
"https://rubygems.org/gems/#{project.name}" + (version ? "/versions/#{version}" : "")
end
def self.download_url(name, version = nil)
"https://rubygems.org/downloads/#{name}-#{version}.gem"
end
def self.documentation_url(name, version = nil)
"http://www.rubydoc.info/gems/#{name}/#{version}"
end
def self.install_instructions(project, version = nil)
"gem install #{project.name}" + (version ? " -v #{version}" : "")
end
def self.check_status_url(project)
"https://rubygems.org/api/v1/versions/#{project.name}.json"
end
def self.project_names
gems = Marshal.load(Gem.gunzip(get_raw("http://production.cf.rubygems.org/specs.4.8.gz")))
gems.map(&:first).uniq
end
def self.recent_names
updated = get('https://rubygems.org/api/v1/activity/just_updated.json').map{|h| h['name']}
new_gems = get('https://rubygems.org/api/v1/activity/latest.json').map{|h| h['name']}
(updated + new_gems).uniq
end
def self.project(name)
get_json("https://rubygems.org/api/v1/gems/#{name}.json")
rescue
{}
end
def self.mapping(project)
{
:name => project["name"],
:description => project["info"],
:homepage => project["homepage_uri"],
:licenses => project.fetch("licenses", []).try(:join, ','),
:repository_url => repo_fallback(project['source_code_uri'],project["homepage_uri"])
}
end
def self.versions(project)
json = get_json("https://rubygems.org/api/v1/versions/#{project['name']}.json")
json.map do |v|
{
:number => v['number'],
:published_at => v['created_at']
}
end
rescue
[]
end
def self.dependencies(name, version, _project)
json = get_json("https://rubygems.org/api/v2/rubygems/#{name}/versions/#{version}.json")
deps = json['dependencies']
map_dependencies(deps['development'], 'Development') + map_dependencies(deps['runtime'], 'runtime')
rescue
[]
end
def self.map_dependencies(deps, kind)
deps.map do |dep|
{
project_name: dep['name'],
requirements: dep['requirements'],
kind: kind,
platform: self.name.demodulize
}
end
end
def self.download_registry_users(name)
json = get_json("https://rubygems.org/api/v1/gems/#{name}/owners.json")
json.map do |user|
{
uuid: user['id'],
email: user['email'],
login: user['handle']
}
end
rescue
[]
end
def self.registry_user_url(login)
"https://rubygems.org/profiles/#{login}"
end
end
end