Class: Repositories::Cargo

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

Constant Summary collapse

HAS_VERSIONS =
true
HAS_DEPENDENCIES =
true
LIBRARIAN_SUPPORT =
true
URL =
'https://crates.io'
COLOR =
'#dea584'

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



45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'app/models/repositories/cargo.rb', line 45

def self.dependencies(name, version)
  deps = get("https://crates.io/api/v1/crates/#{name}/#{version}/dependencies")['dependencies']
  return [] if deps.nil?
  deps.map do |dep|
    {
      project_name: dep['crate_id'],
      requirements: dep['req'],
      kind: dep['kind'],
      optional: dep['optional'],
      platform: self.name.demodulize
    }
  end
end

.mapping(project) ⇒ Object



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

def self.mapping(project)
  {
    :name => project['crate']['id'],
    :homepage => project['crate']['homepage'],
    :description => project['crate']['description'],
    :keywords_array => Array.wrap(project['crate']['keywords']),
    :licenses => project['crate']['license'],
    :repository_url => repo_fallback(project['crate']['repository'], project['crate']['homepage'])
  }
end

.project(name) ⇒ Object



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

def self.project(name)
  get("https://crates.io/api/v1/crates/#{name}")
end

.project_namesObject



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

def self.project_names
  page = 1
  projects = []
  while true
    r = get("https://crates.io/api/v1/crates?page=#{page}&per_page=100")['crates']
    break if r == []
    projects += r
    page +=1
  end
  projects.map{|project| project['name'] }
end

.versions(project) ⇒ Object



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

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