libyear 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6a61e98fbfc381e1f538564dedc9aeb88f42e2de
4
- data.tar.gz: 49136eaae5901712cbab43d2cb837bb1e2feb2bd
3
+ metadata.gz: 10b6af767f2c311397eb8cacc3411ed2faf23a70
4
+ data.tar.gz: 46b24478fedc3efac195e8916389e64db44b269f
5
5
  SHA512:
6
- metadata.gz: 5fc9cf229c5b2a4e3a6ec4670657d6687e560227f03a20677caa2983e410d9fd58daf4639aeb66b04ab02592e6bdc9e35c6920106b64870701d3e9198348f639
7
- data.tar.gz: dee7f5ee73bd7e70f92e92fd8efcf585dfb13e65aaa099a5bfb7a9af760833e3ad53d3efdff663ca2dadbb89761b1218b23fc41e4ee16eaebf9ceebd08e3fa12
6
+ metadata.gz: 568702d22168ad898e48ba88896cbf4f2ba8925549f71baff495342253659af432c39c9913d64480c9dab4f115ebd1bd4255972305279150d72df8cfc7589883
7
+ data.tar.gz: 45a0b87b0ba1c0e3d84e64e6ec1320d090c882f0de4e7ad195b982b99f8044e0aff42fdf02136d21f5882142a18e74f725f2fe8fee0a704080d66abd71fda18f
data/CHANGELOG.md CHANGED
@@ -1,5 +1,25 @@
1
1
  # libyear
2
2
 
3
- ## 0.0.1 (2017-02-13)
3
+ This project follows [semver 2.0.0][1] and the recommendations
4
+ of [keepachangelog.com][2].
5
+
6
+ ## 0.1.1 (2017-02-14)
7
+
8
+ Breaking changes:
9
+
10
+ - None
11
+
12
+ Added:
13
+
14
+ - None
15
+
16
+ Fixed:
17
+
18
+ - Better handling of error when bundle outdated fails
19
+
20
+ ## 0.1.0 (2017-02-13)
4
21
 
5
22
  Initial version. Proof of concept.
23
+
24
+ [1]: http://semver.org/spec/v2.0.0.html
25
+ [2]: http://keepachangelog.com/
data/lib/libyear/cli.rb CHANGED
@@ -1,76 +1,21 @@
1
1
  require "bundler/cli"
2
2
  require "bundler/cli/outdated"
3
+ require "libyear/report"
4
+ require "libyear/query"
3
5
 
4
6
  module Libyear
5
7
  class CLI
6
- # Format of `bundle outdated --parseable` (BOP)
7
- BOP_FMT = /\A(?<name>[^ ]+) \(newest (?<newest>[^,]+), installed (?<installed>[^,)]+)/
8
-
9
8
  def initialize(argv)
10
9
  validate_arguments(argv)
11
10
  @gemfile_path = argv.first
12
11
  end
13
12
 
14
13
  def run
15
- parseable = `BUNDLE_GEMFILE="#{@gemfile_path}" bundle outdated --parseable`
16
- gems = []
17
- parseable.lines.each do |line|
18
- match = BOP_FMT.match(line)
19
- next if match.nil?
20
- gems.push(
21
- installed: { version: match["installed"] },
22
- name: match["name"],
23
- newest: { version: match["newest"] }
24
- )
25
- end
26
- gems.each do |gem|
27
- gem[:installed][:date] = release_date(gem[:name], gem[:installed][:version])
28
- gem[:newest][:date] = release_date(gem[:name], gem[:newest][:version])
29
- end
30
- report(gems)
14
+ print Report.new(Query.new(@gemfile_path).execute).to_s
31
15
  end
32
16
 
33
17
  private
34
18
 
35
- # Known issue: Probably performs a network request every time, unless
36
- # there's some kind of caching.
37
- def release_date(gem_name, gem_version)
38
- dep = ::Bundler::Dependency.new(gem_name, gem_version)
39
- tuples, _errors = ::Gem::SpecFetcher.fetcher.search_for_dependency(dep)
40
- tup, source = tuples.first # Gem::NameTuple
41
- spec = source.fetch_spec(tup) # raises Gem::RemoteFetcher::FetchError
42
- spec.date.to_date
43
- end
44
-
45
- def report(gems)
46
- sum_years = 0.0
47
- gems.each do |gem|
48
- di = gem[:installed][:date]
49
- dn = gem[:newest][:date]
50
- if dn <= di
51
- # Known issue: Backports and maintenance releases of older minor versions.
52
- # Example: json 1.8.6 (2017-01-13) was released *after* 2.0.3 (2017-01-12)
53
- years = 0.0
54
- else
55
- days = (dn - di).to_f
56
- years = days / 365.0
57
- end
58
- sum_years += years
59
- puts(
60
- format(
61
- "%20s%10s%15s%10s%15s%10.1f",
62
- gem[:name],
63
- gem[:installed][:version],
64
- di,
65
- gem[:newest][:version],
66
- dn,
67
- years
68
- )
69
- )
70
- end
71
- puts format("System is %.1f libyears behind", sum_years)
72
- end
73
-
74
19
  def validate_arguments(argv)
75
20
  # todo
76
21
  end
@@ -0,0 +1,73 @@
1
+ require "English"
2
+ require "open3"
3
+
4
+ module Libyear
5
+ # Responsible for getting all the data that goes into the `Report`.
6
+ class Query
7
+ # Format of `bundle outdated --parseable` (BOP)
8
+ BOP_FMT = /\A(?<name>[^ ]+) \(newest (?<newest>[^,]+), installed (?<installed>[^,)]+)/
9
+
10
+ def initialize(gemfile_path)
11
+ @gemfile_path = gemfile_path
12
+ end
13
+
14
+ def execute
15
+ gems = []
16
+ bundle_outdated.lines.each do |line|
17
+ match = BOP_FMT.match(line)
18
+ next if match.nil?
19
+ gems.push(
20
+ installed: { version: match["installed"] },
21
+ name: match["name"],
22
+ newest: { version: match["newest"] }
23
+ )
24
+ end
25
+ gems.each do |gem|
26
+ di = release_date(gem[:name], gem[:installed][:version])
27
+ dn = release_date(gem[:name], gem[:newest][:version])
28
+ if dn <= di
29
+ # Known issue: Backports and maintenance releases of older minor versions.
30
+ # Example: json 1.8.6 (2017-01-13) was released *after* 2.0.3 (2017-01-12)
31
+ years = 0.0
32
+ else
33
+ days = (dn - di).to_f
34
+ years = days / 365.0
35
+ end
36
+ gem[:installed][:date] = di
37
+ gem[:newest][:date] = dn
38
+ gem[:libyears] = years
39
+ end
40
+ gems
41
+ end
42
+
43
+ private
44
+
45
+ def bundle_outdated
46
+ stdout, stderr, status = Open3.capture3(
47
+ %Q(BUNDLE_GEMFILE="#{@gemfile_path}" bundle outdated --parseable)
48
+ )
49
+ # Known statuses:
50
+ # 0 - Nothing is outdated
51
+ # 256 - Something is outdated
52
+ # 1792 - Unable to determine if something is outdated
53
+ unless [0, 256].include?(status.to_i)
54
+ $stderr.puts "`bundle outdated` failed with status: #{status.to_i}"
55
+ $stderr.puts "stderr: #{stderr}"
56
+ $stderr.puts "stdout: #{stdout}"
57
+ $stderr.puts "Try running `bundle install`."
58
+ Kernel.exit(1)
59
+ end
60
+ stdout
61
+ end
62
+
63
+ # Known issue: Probably performs a network request every time, unless
64
+ # there's some kind of caching.
65
+ def release_date(gem_name, gem_version)
66
+ dep = ::Bundler::Dependency.new(gem_name, gem_version)
67
+ tuples, _errors = ::Gem::SpecFetcher.fetcher.search_for_dependency(dep)
68
+ tup, source = tuples.first # Gem::NameTuple
69
+ spec = source.fetch_spec(tup) # raises Gem::RemoteFetcher::FetchError
70
+ spec.date.to_date
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,30 @@
1
+ module Libyear
2
+ # Responsible presenting data from the `Query`. Should only be concerned
3
+ # with presentation, nothing else.
4
+ class Report
5
+ # `gems` - Array of hashes.
6
+ def initialize(gems)
7
+ @gems = gems
8
+ end
9
+
10
+ def to_s
11
+ sum_years = 0.0
12
+ @gems.each do |gem|
13
+ years = gem[:libyears]
14
+ sum_years += years
15
+ puts(
16
+ format(
17
+ "%20s%10s%15s%10s%15s%10.1f",
18
+ gem[:name],
19
+ gem[:installed][:version],
20
+ gem[:installed][:date],
21
+ gem[:newest][:version],
22
+ gem[:newest][:date],
23
+ years
24
+ )
25
+ )
26
+ end
27
+ puts format("System is %.1f libyears behind", sum_years)
28
+ end
29
+ end
30
+ end
@@ -1,3 +1,3 @@
1
1
  module Libyear
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: libyear
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jared Beck
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-02-13 00:00:00.000000000 Z
11
+ date: 2017-02-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -57,6 +57,8 @@ files:
57
57
  - bin/setup
58
58
  - lib/libyear.rb
59
59
  - lib/libyear/cli.rb
60
+ - lib/libyear/query.rb
61
+ - lib/libyear/report.rb
60
62
  - lib/libyear/version.rb
61
63
  - libyear.gemspec
62
64
  homepage: https://libyear.com