Class: GemsBond::Fetchers::RubyGems

Inherits:
Fetcher
  • Object
show all
Defined in:
lib/gems_bond/fetchers/ruby_gems.rb

Overview

Fetches data from RubyGems

Instance Method Summary collapse

Methods inherited from Fetcher

#started?, #stop

Constructor Details

#initialize(name) ⇒ GemsBond::Fetchers::RubyGems

Initializes an instance

Parameters:

  • name (String)

    name of the gem



14
15
16
17
# File 'lib/gems_bond/fetchers/ruby_gems.rb', line 14

def initialize(name)
  super(name)
  @name = name
end

Instance Method Details

#days_since_last_versionInteger

Returns number of days since last version

Returns:

  • (Integer)


75
76
77
78
79
# File 'lib/gems_bond/fetchers/ruby_gems.rb', line 75

def days_since_last_version
  return unless last_version_date

  Integer(Date.today - last_version_date)
end

#downloads_countInteger

Returns number of downloads

Returns:

  • (Integer)


38
39
40
# File 'lib/gems_bond/fetchers/ruby_gems.rb', line 38

def downloads_count
  Gems.total_downloads(@name)[:total_downloads]
end

#infoString

Returns gem description

Returns:

  • (String)


32
33
34
# File 'lib/gems_bond/fetchers/ruby_gems.rb', line 32

def info
  @info["info"]
end

#last_versionString

Returns last version number

Returns:

  • (String)


63
64
65
# File 'lib/gems_bond/fetchers/ruby_gems.rb', line 63

def last_version
  versions&.first&.dig(:number)
end

#last_version_dateDate

Returns last version date

Returns:

  • (Date)


69
70
71
# File 'lib/gems_bond/fetchers/ruby_gems.rb', line 69

def last_version_date
  versions&.first&.dig(:created_at)
end

#source_code_uriString

Returns source code URI

Returns:

  • (String)


44
45
46
# File 'lib/gems_bond/fetchers/ruby_gems.rb', line 44

def source_code_uri
  @info["source_code_uri"]
end

#startBoolean

Note:

rescue connection errors with nil

Starts the service

Returns:

  • (Boolean)


22
23
24
25
26
27
28
# File 'lib/gems_bond/fetchers/ruby_gems.rb', line 22

def start
  super
  # ensure gem exists (otherwise it raises Gems error)
  @info = Gems.info(@name)
rescue Gems::NotFound
  stop
end

#versionsArray<Hash>

Note:

each hash structure: { number: String, created_at: Date, prerelease: Boolean }

Returns versions data (number, date and if it is a prerelease)

Returns:

  • (Array<Hash>)


51
52
53
54
55
56
57
58
59
# File 'lib/gems_bond/fetchers/ruby_gems.rb', line 51

def versions
  Gems.versions(@name).map do |version|
    {
      number: version["number"],
      created_at: Date.parse(version["created_at"]),
      prerelease: version["prerelease"]
    }
  end
end