Class: Repositories::Dub

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

Constant Summary collapse

HAS_VERSIONS =
true
HAS_DEPENDENCIES =
true
LIBRARIAN_SUPPORT =
true
URL =
'http://code.dlang.org'
COLOR =
'#fcd46d'

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

.acceptable_versions(project) ⇒ Object



38
39
40
41
42
# File 'app/models/repositories/dub.rb', line 38

def self.acceptable_versions(project)
  project['versions'].select do |version|
    (version['version'] =~ /^~.*/i).nil?
  end
end

.dependencies(name, version) ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'app/models/repositories/dub.rb', line 58

def self.dependencies(name, version)
  vers = project(name)['versions'].find{|v| v['version'] == version}
  return [] if vers.nil?
  deps = vers['dependencies']
  return [] if deps.nil?
  deps.map do |k,v|
    if v.is_a? Hash
      req = v["version"]
      optional = v["optional"]
    else
      req = v
      optional = false
    end
    {
      project_name: k,
      requirements: req,
      kind: 'normal',
      optional: optional,
      platform: self.name.demodulize
    }
  end
end

.format_keywords(categories) ⇒ Object



54
55
56
# File 'app/models/repositories/dub.rb', line 54

def self.format_keywords(categories)
  Array.wrap(categories).join('.').split('.').map(&:downcase).uniq
end

.mapping(project) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
# File 'app/models/repositories/dub.rb', line 17

def self.mapping(project)
  latest_version = project["versions"].last
  {
    :name => project["name"],
    :description => latest_version['description'],
    :homepage => latest_version['homepage'],
    :keywords_array => format_keywords(project["categories"]),
    :licenses => latest_version['license'],
    :repository_url => repo_fallback(repository(project["repository"]),latest_version['homepage'])
  }
end

.project(name) ⇒ Object



13
14
15
# File 'app/models/repositories/dub.rb', line 13

def self.project(name)
  get("http://code.dlang.org/packages/#{name}.json")
end

.project_namesObject



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

def self.project_names
  get("http://code.dlang.org/packages/index.json").sort
end

.repository(hash) ⇒ Object



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

def self.repository(hash)
  if hash['kind'] == 'github'
    "https://github.com/#{hash['owner']}/#{hash['project']}"
  elsif hash['kind'] == 'bitbucket'
    "https://bitbucket.org/#{hash['owner']}/#{hash['project']}"
  else
    ''
  end
end

.versions(project) ⇒ Object



29
30
31
32
33
34
35
36
# File 'app/models/repositories/dub.rb', line 29

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