Class: Repositories::Hex

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

Constant Summary collapse

HAS_VERSIONS =
true
HAS_DEPENDENCIES =
true
LIBRARIAN_SUPPORT =
true
URL =
'https://hex.pm'
COLOR =
'#6e4a7e'

Constants inherited from Base

Base::HIDDEN, Base::LIBRARIAN_PLANNED, Base::SECURITY_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


53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'app/models/repositories/hex.rb', line 53

def self.dependencies(name, version)
  deps = get("https://hex.pm/api/packages/#{name}/releases/#{version}")['requirements']
  return [] if deps.nil?
  deps.map do |k, v|
    {
      project_name: k,
      requirements: v['requirement'],
      kind: 'normal',
      optional: v['optional'],
      platform: self.name.demodulize
    }
  end
end

.mapping(project) ⇒ Object


31
32
33
34
35
36
37
38
39
40
41
42
# File 'app/models/repositories/hex.rb', line 31

def self.mapping(project)
  links = project["meta"].fetch("links", {}).each_with_object({}) do |(k, v), h|
    h[k.downcase] = v
  end
  {
    :name => project["name"],
    :homepage => links.except('github').first.try(:last),
    :repository_url => links['github'],
    :description => project["meta"]["description"],
    :licenses => repo_fallback(project["meta"].fetch("licenses", []).join(','), links.except('github').first.try(:last))
  }
end

.project(name) ⇒ Object


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

def self.project(name)
  sleep 30
  get("https://hex.pm/api/packages/#{name}")
end

.project_namesObject


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

def self.project_names
  page = 1
  projects = []
  while true
    r = get("https://hex.pm/api/packages?page=#{page}")
    break if r == []
    projects += r
    page +=1
  end
  projects.map{|project| project['name'] }
end

.recent_namesObject


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

def self.recent_names
  (get('https://hex.pm/api/packages?sort=inserted_at').map{|project| project['name'] } +
  get('https://hex.pm/api/packages?sort=updated_at').map{|project| project['name'] }).uniq
end

.versions(project) ⇒ Object


44
45
46
47
48
49
50
51
# File 'app/models/repositories/hex.rb', line 44

def self.versions(project)
  project["releases"].map do |version|
    {
      :number => version['version'],
      :published_at => version['inserted_at']
    }
  end
end