Class: Ossert::Fetch::Rubygems

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/ossert/fetch/rubygems.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(project) ⇒ Rubygems

Returns a new instance of Rubygems.



10
11
12
13
# File 'lib/ossert/fetch/rubygems.rb', line 10

def initialize(project)
  @client = SimpleClient.new('https://rubygems.org/api/v1/')
  @project = project
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



5
6
7
# File 'lib/ossert/fetch/rubygems.rb', line 5

def client
  @client
end

#projectObject (readonly)

Returns the value of attribute project.



5
6
7
# File 'lib/ossert/fetch/rubygems.rb', line 5

def project
  @project
end

Instance Method Details

#infoObject



15
16
17
# File 'lib/ossert/fetch/rubygems.rb', line 15

def info
  @info ||= client.get("gems/#{project.rubygems_alias}.json")
end

#processObject



69
70
71
72
73
74
75
76
77
# File 'lib/ossert/fetch/rubygems.rb', line 69

def process
  process_github_alias

  process_dependencies
  process_releases

  process_meta
  process_links
end

#process_dependenciesObject



64
65
66
67
# File 'lib/ossert/fetch/rubygems.rb', line 64

def process_dependencies
  agility.total.dependencies = Set.new(info['dependencies']['runtime']).to_a
  community.total.dependants = Set.new(reversed_dependencies).to_a
end

#process_github_aliasObject



50
51
52
53
54
55
# File 'lib/ossert/fetch/rubygems.rb', line 50

def process_github_alias
  return unless project.github_alias.blank?
  match = info['source_code_uri'].try(:match, %r{github.com/([a-zA-Z0-9\.\_\-]+)/([a-zA-Z0-9\.\_\-]+)})
  match ||= info['homepage_uri'].try(:match, %r{github.com/([a-zA-Z0-9\.\_\-]+)/([a-zA-Z0-9\.\_\-]+)})
  project.github_alias = match ? "#{match[1]}/#{match[2]}" : NO_GITHUB_NAME
end


37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/ossert/fetch/rubygems.rb', line 37

def process_links
  meta.merge!(
    homepage_url: info['homepage_uri'],
    docs_url: info['documentation_uri'],
    wiki_url: info['wiki_uri'],
    source_url: info['source_code_uri'],
    issue_tracker_url: info['bug_tracker_uri'],
    mailing_list_url: info['mailing_list_uri'],
    rubygems_url: info['project_uri'],
    github_url: "https://github.com/#{project.github_alias}" # or exception!
  )
end

#process_metaObject



31
32
33
34
35
# File 'lib/ossert/fetch/rubygems.rb', line 31

def process_meta
  meta[:authors] = info['authors']
  meta[:description] = info['info']
  meta[:current_version] = info['version']
end

#process_releasesObject



57
58
59
60
61
62
# File 'lib/ossert/fetch/rubygems.rb', line 57

def process_releases
  releases.each do |release|
    agility.total.releases_total_rg << release['number']
    agility.quarters[release['created_at']].releases_total_rg << release['number']
  end
end

#releasesObject



23
24
25
# File 'lib/ossert/fetch/rubygems.rb', line 23

def releases
  @releases ||= client.get("versions/#{project.rubygems_alias}.json")
end

#reversed_dependenciesObject



27
28
29
# File 'lib/ossert/fetch/rubygems.rb', line 27

def reversed_dependencies
  client.get("/gems/#{project.rubygems_alias}/reverse_dependencies.json")
end

#version_infoObject



19
20
21
# File 'lib/ossert/fetch/rubygems.rb', line 19

def version_info
  @info ||= client.get("versions/#{project.rubygems_alias}.json")
end