Class: GemsBond::Fetchers::RubyGems
- Defined in:
- lib/gems_bond/fetchers/ruby_gems.rb
Overview
Fetches data from RubyGems
Instance Method Summary collapse
-
#days_since_last_version ⇒ Integer
Returns number of days since last version.
-
#downloads_count ⇒ Integer
Returns number of downloads.
-
#info ⇒ String
Returns gem description.
-
#initialize(name) ⇒ GemsBond::Fetchers::RubyGems
constructor
Initializes an instance.
-
#last_version ⇒ String
Returns last version number.
-
#last_version_date ⇒ Date
Returns last version date.
-
#source_code_uri ⇒ String
Returns source code URI.
-
#start ⇒ Boolean
Starts the service.
-
#versions ⇒ Array<Hash>
Returns versions data (number, date and if it is a prerelease).
Methods inherited from Fetcher
Constructor Details
#initialize(name) ⇒ GemsBond::Fetchers::RubyGems
Initializes an instance
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_version ⇒ Integer
Returns number of days since last version
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_count ⇒ Integer
Returns number of downloads
38 39 40 |
# File 'lib/gems_bond/fetchers/ruby_gems.rb', line 38 def downloads_count Gems.total_downloads(@name)[:total_downloads] end |
#info ⇒ String
Returns gem description
32 33 34 |
# File 'lib/gems_bond/fetchers/ruby_gems.rb', line 32 def info @info["info"] end |
#last_version ⇒ String
Returns last version number
63 64 65 |
# File 'lib/gems_bond/fetchers/ruby_gems.rb', line 63 def last_version versions&.first&.dig(:number) end |
#last_version_date ⇒ Date
Returns last version 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_uri ⇒ String
Returns source code URI
44 45 46 |
# File 'lib/gems_bond/fetchers/ruby_gems.rb', line 44 def source_code_uri @info["source_code_uri"] end |
#start ⇒ Boolean
Note:
rescue connection errors with nil
Starts the service
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 |
#versions ⇒ Array<Hash>
Note:
each hash structure: { number: String, created_at: Date, prerelease: Boolean }
Returns versions data (number, date and if it is a prerelease)
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 |