Class: Libyear::Query
- Inherits:
-
Object
- Object
- Libyear::Query
- Defined in:
- lib/libyear/query.rb
Overview
Responsible for getting all the data that goes into the ‘Report`.
Constant Summary collapse
- BOP_FMT =
Format of ‘bundle outdated –parseable` (BOP)
/\A(?<name>[^ ]+) \(newest (?<newest>[^,]+), installed (?<installed>[^,)]+)/
Instance Method Summary collapse
- #execute ⇒ Object
-
#initialize(gemfile_path) ⇒ Query
constructor
A new instance of Query.
Constructor Details
#initialize(gemfile_path) ⇒ Query
Returns a new instance of Query.
10 11 12 |
# File 'lib/libyear/query.rb', line 10 def initialize(gemfile_path) @gemfile_path = gemfile_path end |
Instance Method Details
#execute ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/libyear/query.rb', line 14 def execute gems = [] bundle_outdated.lines.each do |line| match = BOP_FMT.match(line) next if match.nil? gems.push( installed: { version: match["installed"] }, name: match["name"], newest: { version: match["newest"] } ) end gems.each do |gem| di = release_date(gem[:name], gem[:installed][:version]) dn = release_date(gem[:name], gem[:newest][:version]) gem[:installed][:date] = di gem[:newest][:date] = dn if di.nil? || dn.nil? || dn <= di # Known issue: Backports and maintenance releases of older minor versions. # Example: json 1.8.6 (2017-01-13) was released *after* 2.0.3 (2017-01-12) years = 0.0 else days = (dn - di).to_f years = days / 365.0 end gem[:libyears] = years end gems end |