gem_dating 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 240b4b51a3ff7ea51e8f5133c5980b857656499d37cb9dca2e427f084f5d8e9f
4
+ data.tar.gz: 3bee7a49cb6cff56b5ca793cd49103c2e16f60a74dcb8c98313e83c4c3bde008
5
+ SHA512:
6
+ metadata.gz: 350ac78f61900661889eeb66bb3f4ccf9d54d752d8d9034aa910e40827aa3faf0ff8e96c67db75df8a67413e8f18dcdae3359685a45a48d26e68f67133228962
7
+ data.tar.gz: b03e680f2824c6e8a6a67bc3a8664946e00e5bf881ce1a4977b9e851b5a0596806b55abd6c6272ce737e43c5e499e276e2bb7f3784001c5533c1ad3ffa3cef86
@@ -0,0 +1,22 @@
1
+ name: Ruby
2
+
3
+ on: push
4
+
5
+ jobs:
6
+ build:
7
+ runs-on: ubuntu-latest
8
+ name: Ruby ${{ matrix.ruby }}
9
+ strategy:
10
+ matrix:
11
+ ruby:
12
+ - '3.2.1'
13
+
14
+ steps:
15
+ - uses: actions/checkout@v3
16
+ - name: Set up Ruby
17
+ uses: ruby/setup-ruby@v1
18
+ with:
19
+ ruby-version: ${{ matrix.ruby }}
20
+ bundler-cache: true
21
+ - name: Run the default task
22
+ run: bundle exec rake
data/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ ruby-3.2
data/CHANGELOG.md ADDED
@@ -0,0 +1,8 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2023-06-23
4
+
5
+ - Initial release
6
+ - Ability to parse a string or file for gems
7
+ - Three output formats: [Gem::Specification], hash, table representation
8
+ - CLI wrapper (thanks @Daniel-N-Huss)
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in gem_dating.gemspec
4
+ gemspec
5
+
6
+ gem "rake"
7
+ gem "minitest"
8
+ gem "standard"
9
+ gem "m"
10
+ gem "mocktail"
data/Gemfile.lock ADDED
@@ -0,0 +1,71 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ gem_dating (0.1.0)
5
+ bundler
6
+ table_print
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ ast (2.4.2)
12
+ json (2.6.3)
13
+ language_server-protocol (3.17.0.3)
14
+ lint_roller (1.0.0)
15
+ m (1.6.1)
16
+ method_source (>= 0.6.7)
17
+ rake (>= 0.9.2.2)
18
+ method_source (1.0.0)
19
+ minitest (5.18.0)
20
+ mocktail (1.2.2)
21
+ parallel (1.23.0)
22
+ parser (3.2.2.1)
23
+ ast (~> 2.4.1)
24
+ rainbow (3.1.1)
25
+ rake (13.0.6)
26
+ regexp_parser (2.8.0)
27
+ rexml (3.2.5)
28
+ rubocop (1.50.2)
29
+ json (~> 2.3)
30
+ parallel (~> 1.10)
31
+ parser (>= 3.2.0.0)
32
+ rainbow (>= 2.2.2, < 4.0)
33
+ regexp_parser (>= 1.8, < 3.0)
34
+ rexml (>= 3.2.5, < 4.0)
35
+ rubocop-ast (>= 1.28.0, < 2.0)
36
+ ruby-progressbar (~> 1.7)
37
+ unicode-display_width (>= 2.4.0, < 3.0)
38
+ rubocop-ast (1.28.1)
39
+ parser (>= 3.2.1.0)
40
+ rubocop-performance (1.16.0)
41
+ rubocop (>= 1.7.0, < 2.0)
42
+ rubocop-ast (>= 0.4.0)
43
+ ruby-progressbar (1.13.0)
44
+ standard (1.28.2)
45
+ language_server-protocol (~> 3.17.0.2)
46
+ lint_roller (~> 1.0)
47
+ rubocop (~> 1.50.2)
48
+ standard-custom (~> 1.0.0)
49
+ standard-performance (~> 1.0.1)
50
+ standard-custom (1.0.0)
51
+ lint_roller (~> 1.0)
52
+ standard-performance (1.0.1)
53
+ lint_roller (~> 1.0)
54
+ rubocop-performance (~> 1.16.0)
55
+ table_print (1.5.7)
56
+ unicode-display_width (2.4.2)
57
+
58
+ PLATFORMS
59
+ arm64-darwin-22
60
+ x86_64-linux
61
+
62
+ DEPENDENCIES
63
+ gem_dating!
64
+ m
65
+ minitest
66
+ mocktail
67
+ rake
68
+ standard
69
+
70
+ BUNDLED WITH
71
+ 2.4.12
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2023 Steve Jackson
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,92 @@
1
+ # GemDating
2
+
3
+ GemDating is a library for determining the relative age of a set of gems.
4
+
5
+ The primary use case is when evaluating a codebase for upgrades - a gem from 2017 may effectively be abandoned and could
6
+ cause trouble if you're targeting an upgrade to Ruby 4.1
7
+
8
+ ## Usage
9
+
10
+ ### Installation
11
+
12
+ `gem install gem_dating` or add it to your Gemfile:
13
+
14
+ ```ruby
15
+ gem 'gem_dating', group: [:development]
16
+ ```
17
+
18
+ ### Running GemDating
19
+
20
+ This gem provides a *very* limited command line interface. It may be invoked with:
21
+
22
+ ```bash
23
+ $ gem_dating [path/to/Gemfile]
24
+ ```
25
+
26
+ Given a path to a Gemfile, GemDating will output a list of gems and their relative ages to the stdout stream.
27
+
28
+ For example:
29
+
30
+ ```bash
31
+ $ gem_dating ~/code/my_app/Gemfile
32
+ ```
33
+ to read the output in your terminal.
34
+
35
+ Or you can run
36
+ ```bash
37
+ $ gem_dating ~/code/my_app/Gemfile > ~/code/my_app/gem_ages.txt
38
+ ```
39
+ which will pipe the output into a text file.
40
+
41
+ The command line output will look something like this:
42
+
43
+ ```bash
44
+ NAME | VERSION | DATE
45
+ ------------|---------|-----------
46
+ rest-client | 2.1.0 | 2019-08-21
47
+ rails | 7.0.5 | 2023-05-24
48
+ graphql | 2.0.22 | 2023-05-17
49
+ ```
50
+
51
+ gem_dating also includes some other useable patterns, if you invoke it within an IRB session. It currently supports
52
+ passing in a string of a gem name, or a path to a Gemfile. You can then parse those to an array of `Gem::Specifications`,
53
+ a minimal hash, or the Table output you'd see in the CLI.
54
+
55
+ ```ruby
56
+ # irb
57
+ # #:001 >
58
+
59
+ require "gem_dating"
60
+
61
+ dating = GemDating.from_string("rails")
62
+
63
+ more_dating = GemDating.from_file("path/to/Gemfile")
64
+
65
+
66
+ dating.to_a
67
+ # => [Gem::Specification.new do |s|
68
+ # s.name = "rails"
69
+ # s.version = Gem::Version.new("7.0.5")
70
+ # s.installed_by_version = Gem::Version.new("0") ...etc
71
+
72
+ dating.to_h
73
+ # => {"rails"=>{"name"=>"rails", "version"=>"7.0.5", "date"=>"2023-05-24"}}
74
+
75
+ more_dating.table_print
76
+ # =>
77
+ # NAME | VERSION | DATE
78
+ # ------------|---------|-----------
79
+ # rails | 7.0.5 | 2023-05-24
80
+ # ...etc
81
+ ```
82
+
83
+
84
+
85
+ ## Code of Conduct
86
+
87
+ This project follows Test Double's [code of
88
+ conduct](https://testdouble.com/code-of-conduct) for all community interactions,
89
+ including (but not limited to) one-on-one communications, public posts/comments,
90
+ code reviews, pull requests, and GitHub issues. If violations occur, Test Double
91
+ will take any action they deem appropriate for the infraction, up to and
92
+ including blocking a user from the organization's repositories.
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList["test/**/*_test.rb"]
8
+ end
9
+
10
+ task :default => :test
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "gem_dating"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/exe/gem_dating ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $LOAD_PATH.unshift("#{__dir__}/../lib")
4
+
5
+ require "gem_dating"
6
+
7
+ exit GemDating::Cli.new(ARGV).run
@@ -0,0 +1,29 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "gem_dating/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "gem_dating"
8
+ spec.version = GemDating::VERSION
9
+ spec.authors = ["Steve Jackson", "Daniel Huss"]
10
+ spec.email = ["steve@testdouble.com"]
11
+
12
+ spec.summary = "How old is that anyway?"
13
+ spec.homepage = "https://github.com/testdouble/gem_dating"
14
+ spec.license = "MIT"
15
+
16
+ spec.metadata["homepage_uri"] = spec.homepage
17
+ spec.metadata["source_code_uri"] = spec.homepage
18
+ spec.metadata["changelog_uri"] = "#{spec.homepage}/blob/main/CHANGELOG.md"
19
+
20
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
21
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
22
+ end
23
+ spec.bindir = "exe"
24
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
25
+ spec.require_paths = ["lib"]
26
+
27
+ spec.add_dependency "bundler"
28
+ spec.add_dependency "table_print"
29
+ end
@@ -0,0 +1,23 @@
1
+ module GemDating
2
+ class Cli
3
+ SUCCESS = 0
4
+ GENERAL_ERROR = 1
5
+
6
+ def initialize(argv)
7
+ @argv = argv
8
+ end
9
+
10
+ def run
11
+ if @argv.empty?
12
+ $stdout << "Usage: gem_dating [GEMFILE_FILEPATH]\n"
13
+ return GENERAL_ERROR
14
+ end
15
+
16
+ path = @argv.first
17
+
18
+ $stdout << GemDating.from_file(path).table_print << "\n"
19
+
20
+ SUCCESS
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,43 @@
1
+ module GemDating
2
+ class Input
3
+ def self.string(s)
4
+ new(s)
5
+ end
6
+
7
+ def self.file(path)
8
+ new(IO.read(path))
9
+ end
10
+
11
+ attr_reader :contents
12
+
13
+ def initialize(contents)
14
+ @contents = contents
15
+ end
16
+
17
+ def gems
18
+ lines = contents.split("\n")
19
+ lines.each_with_object([]) do |line, gems|
20
+ line = gem_line(line.strip)
21
+ gems << cleanup(line) if line
22
+ end
23
+ end
24
+
25
+ def gem_line(line)
26
+ return if line.strip == "end"
27
+
28
+ if line.start_with? "gem("
29
+ line.split("(")[1].split(",")[0]
30
+ elsif line.start_with? "gem"
31
+ line.split[1].split(",")[0]
32
+ elsif line.split.length == 1
33
+ line
34
+ end
35
+ end
36
+
37
+ def cleanup(line)
38
+ # "foo",
39
+ # 'hi'
40
+ line.strip.chomp(",").chomp("'").chomp('"').delete_prefix("'").delete_prefix('"')
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,28 @@
1
+ require "table_print"
2
+
3
+ module GemDating
4
+ class Result
5
+ attr_reader :specs
6
+ def initialize(specs)
7
+ @specs = specs
8
+ end
9
+
10
+ def to_a
11
+ specs
12
+ end
13
+
14
+ def to_h
15
+ specs.each_with_object({}) do |spec, result|
16
+ result[spec.name] = {
17
+ "name" => spec.name,
18
+ "version" => spec.version.to_s,
19
+ "date" => spec.date.strftime("%Y-%m-%d")
20
+ }
21
+ end
22
+ end
23
+
24
+ def table_print
25
+ TablePrint::Printer.table_print(specs, [:name, :version, {date: {time_format: "%Y-%m-%d", width: 10}}]).encode("utf-8")
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,21 @@
1
+ module GemDating
2
+ class Rubygems
3
+ def self.fetch(...)
4
+ new.fetch(...)
5
+ end
6
+
7
+ def fetch(gems)
8
+ gems.map do |gem|
9
+ Gem.latest_spec_for(gem) || unknown_version(gem)
10
+ end
11
+ end
12
+
13
+ def unknown_version(gemname)
14
+ Gem::Specification.new do |s|
15
+ s.name = gemname
16
+ s.version = "0.0.0.UNKNOWN"
17
+ s.date = "1970-01-01"
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,3 @@
1
+ module GemDating
2
+ VERSION = "0.1.0"
3
+ end
data/lib/gem_dating.rb ADDED
@@ -0,0 +1,19 @@
1
+ require "gem_dating/version"
2
+ require_relative "gem_dating/input"
3
+ require_relative "gem_dating/rubygems"
4
+ require_relative "gem_dating/result"
5
+ require_relative "gem_dating/cli"
6
+
7
+ module GemDating
8
+ def self.from_string(s)
9
+ gems = Input.string(s).gems
10
+ specs = Rubygems.fetch(gems)
11
+ Result.new(specs)
12
+ end
13
+
14
+ def self.from_file(path)
15
+ gems = Input.file(path).gems
16
+ specs = Rubygems.fetch(gems)
17
+ Result.new(specs)
18
+ end
19
+ end
metadata ADDED
@@ -0,0 +1,95 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gem_dating
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Steve Jackson
8
+ - Daniel Huss
9
+ autorequire:
10
+ bindir: exe
11
+ cert_chain: []
12
+ date: 2023-07-19 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ">="
19
+ - !ruby/object:Gem::Version
20
+ version: '0'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ version: '0'
28
+ - !ruby/object:Gem::Dependency
29
+ name: table_print
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ description:
43
+ email:
44
+ - steve@testdouble.com
45
+ executables:
46
+ - gem_dating
47
+ extensions: []
48
+ extra_rdoc_files: []
49
+ files:
50
+ - ".github/workflows/main.yml"
51
+ - ".gitignore"
52
+ - ".ruby-version"
53
+ - CHANGELOG.md
54
+ - Gemfile
55
+ - Gemfile.lock
56
+ - LICENSE.txt
57
+ - README.md
58
+ - Rakefile
59
+ - bin/console
60
+ - bin/setup
61
+ - exe/gem_dating
62
+ - gem_dating.gemspec
63
+ - lib/gem_dating.rb
64
+ - lib/gem_dating/cli.rb
65
+ - lib/gem_dating/input.rb
66
+ - lib/gem_dating/result.rb
67
+ - lib/gem_dating/rubygems.rb
68
+ - lib/gem_dating/version.rb
69
+ homepage: https://github.com/testdouble/gem_dating
70
+ licenses:
71
+ - MIT
72
+ metadata:
73
+ homepage_uri: https://github.com/testdouble/gem_dating
74
+ source_code_uri: https://github.com/testdouble/gem_dating
75
+ changelog_uri: https://github.com/testdouble/gem_dating/blob/main/CHANGELOG.md
76
+ post_install_message:
77
+ rdoc_options: []
78
+ require_paths:
79
+ - lib
80
+ required_ruby_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ required_rubygems_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ requirements: []
91
+ rubygems_version: 3.4.6
92
+ signing_key:
93
+ specification_version: 4
94
+ summary: How old is that anyway?
95
+ test_files: []