Class: Repositories::CPAN

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

Constant Summary collapse

HAS_VERSIONS =
true
HAS_DEPENDENCIES =
false
LIBRARIAN_SUPPORT =
true
URL =
'https://metacpan.org'
COLOR =
'#0298c3'

Constants inherited from Base

Base::HIDDEN, Base::LIBRARIAN_PLANNED, Base::SECURITY_PLANNED

Class Method Summary collapse

Methods inherited from Base

color, dependencies, 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

.mapping(project) ⇒ Object


30
31
32
33
34
35
36
37
38
# File 'app/models/repositories/cpan.rb', line 30

def self.mapping(project)
  {
    :name => project['distribution'],
    :homepage => project.fetch('resources',{})['homepage'],
    :description => project['abstract'],
    :licenses => project['license'].join(','),
    :repository_url => repo_fallback(project.fetch('resources',{}).fetch('repository',{})['web'], project.fetch('resources',{})['homepage'])
  }
end

.project(name) ⇒ Object


26
27
28
# File 'app/models/repositories/cpan.rb', line 26

def self.project(name)
  get("http://api.metacpan.org/v0/release/#{name}")
end

.project_namesObject


9
10
11
12
13
14
15
16
17
18
19
# File 'app/models/repositories/cpan.rb', line 9

def self.project_names
  page = 1
  projects = []
  while true
    r = get("http://api.metacpan.org/v0/release/_search?q=status:latest&fields=distribution&sort=date:desc&size=5000&from=#{page*5000}")['hits']['hits']
    break if r == []
    projects += r
    page +=1
  end
  projects.map{|project| project['fields']['distribution'] }.uniq
end

.recent_namesObject


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

def self.recent_names
  names = get('http://api.metacpan.org/v0/release/_search?q=status:latest&fields=distribution&sort=date:desc&size=100')['hits']['hits']
  names.map{|project| project['fields']['distribution'] }.uniq
end

.versions(project) ⇒ Object


40
41
42
43
44
45
# File 'app/models/repositories/cpan.rb', line 40

def self.versions(project)
  [{
    :number => project['version'],
    :published_at => project['date']
  }]
end