Class: Repositories::Jam

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

Constant Summary collapse

HAS_VERSIONS =
true
HAS_DEPENDENCIES =
false
SECURITY_PLANNED =
true
URL =
'http://jamjs.org/'
COLOR =
'#f1e05a'

Constants inherited from Base

Base::HIDDEN, Base::LIBRARIAN_PLANNED, Base::LIBRARIAN_SUPPORT

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
39
40
41
# File 'app/models/repositories/jam.rb', line 30

def self.mapping(project)
  return false unless project["versions"].present?
  latest_version = project["versions"].to_a.last[1]
  {
    :name => project["name"],
    :description => project["description"],
    :homepage => project["homepage"],
    :keywords_array => Array.wrap(project.fetch("keywords", [])),
    :licenses => latest_version.fetch('licenses', []).map{|l| l['type'] }.join(','),
    :repository_url => repo_fallback(latest_version.fetch('repository', {})['url'],project["homepage"])
  }
end

.project(name) ⇒ Object



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

def self.project(name)
  get("http://jamjs.org/repository/#{name}")
end

.project_namesObject



9
10
11
# File 'app/models/repositories/jam.rb', line 9

def self.project_names
  projects.keys.sort
end

.projectsObject



13
14
15
16
17
18
19
20
21
22
23
24
# File 'app/models/repositories/jam.rb', line 13

def self.projects
  @projects ||= begin
    prjcts = {}
    packages = get_json("http://jamjs.org/repository/_design/jam-packages/_view/packages_by_category?reduce=false&include_docs=true&startkey=%5B%22All%22%5D&endkey=%5B%22All%22%2C%7B%7D%5D&limit=2000&skip=0")['rows']

    packages.each do |package|
      prjcts[package['id'].downcase] = package['doc']
    end

    prjcts
  end
end

.versions(project) ⇒ Object



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

def self.versions(project)
  project['time'].except("modified", "created").map do |k,v|
    {
      :number => k,
      :published_at => v
    }
  end
end