Class: Repositories::Rubygems

Inherits:
Base
  • Object
show all
Defined in:
app/models/repositories/rubygems.rb

Constant Summary collapse

HAS_VERSIONS =
true
HAS_DEPENDENCIES =
true
LIBRARIAN_SUPPORT =
true
SECURITY_PLANNED =
true
URL =
'https://rubygems.org'
COLOR =
'#701516'

Constants inherited from Base

Base::HIDDEN, Base::LIBRARIAN_PLANNED

Class Method Summary collapse

Methods inherited from Base

color, download_dependencies, formatted_name, get, get_html, get_json, get_raw, import, import_async, import_new, import_new_async, import_recent, import_recent_async, new_names, package_link, repo_fallback, save, save_dependencies, update

Class Method Details

.dependencies(name, version) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'app/models/repositories/rubygems.rb', line 44

def self.dependencies(name, version)
  g = Gems.info(name)
  return [] unless g['version'] == version

  deps = g['dependencies']
  d = []
  deps['development'].each do |dep|
    d <<  {
      project_name: dep['name'],
      requirements: dep['requirements'],
      kind: 'Development',
      platform: self.name.demodulize
    }
  end
  deps['runtime'].each do |dep|
    d <<  {
      project_name: dep['name'],
      requirements: dep['requirements'],
      kind: 'normal',
      platform: self.name.demodulize
    }
  end
  d
end

.mapping(project) ⇒ Object



25
26
27
28
29
30
31
32
33
# File 'app/models/repositories/rubygems.rb', line 25

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

.project(name) ⇒ Object



21
22
23
# File 'app/models/repositories/rubygems.rb', line 21

def self.project(name)
  Gems.info name
end

.project_namesObject



10
11
12
13
# File 'app/models/repositories/rubygems.rb', line 10

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

.recent_namesObject



15
16
17
18
19
# File 'app/models/repositories/rubygems.rb', line 15

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

.versions(project) ⇒ Object



35
36
37
38
39
40
41
42
# File 'app/models/repositories/rubygems.rb', line 35

def self.versions(project)
  Gems.versions(project['name']).map do |v|
    {
      :number => v['number'],
      :published_at => v['created_at']
    }
  end
end