Skip to content

Commit

Permalink
Merge pull request #1 from Daniel-N-Huss/command_line_and_readme_stuff
Browse files Browse the repository at this point in the history
Command line and readme stuff
  • Loading branch information
stevenjackson authored Jun 22, 2023
2 parents 75c5881 + 58215b3 commit 6769d06
Show file tree
Hide file tree
Showing 9 changed files with 175 additions and 74 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ gem "rake"
gem "minitest"
gem "standard"
gem "m"
gem "mocktail"
2 changes: 2 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ GEM
rake (>= 0.9.2.2)
method_source (1.0.0)
minitest (5.18.0)
mocktail (1.2.2)
parallel (1.23.0)
parser (3.2.2.1)
ast (~> 2.4.1)
Expand Down Expand Up @@ -64,6 +65,7 @@ DEPENDENCIES
gem_dating!
m
minitest
mocktail
rake
standard

Expand Down
68 changes: 66 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

GemDating is a library for determining the relative age of a set of gems.

The primary use case is when evaluating a codebase for upgrades - a gem from 2017 may effectively be abandoned and could cause trouble if you're targeting an upgrade to Ruby 4.1
The primary use case is when evaluating a codebase for upgrades - a gem from 2017 may effectively be abandoned and could
cause trouble if you're targeting an upgrade to Ruby 4.1

## Usage

Expand All @@ -15,7 +16,70 @@ gem 'gem_dating', group: [:development]
```

### Running GemDating
TODO: much explaining

This gem provides a *very* limited command line interface. It may be invoked with:

```bash
$ gem_dating [path/to/Gemfile]
```

Given a path to a Gemfile, GemDating will output a list of gems and their relative ages to the stdout stream.

For example:

```bash
$ gem_dating ~/code/my_app/Gemfile
```
to read the output in your terminal.

Or you can run
```bash
$ gem_dating ~/code/my_app/Gemfile > ~/code/my_app/gem_ages.txt
```
which will pipe the output into a text file.

The command line output will look something like this:

```bash
NAME | VERSION | DATE
------------|---------|-----------
rest-client | 2.1.0 | 2019-08-21
rails | 7.0.5 | 2023-05-24
graphql | 2.0.22 | 2023-05-17
```

gem_dating also includes some other useable patterns, if you invoke it within an IRB session. It currently supports
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`,
a minimal hash, or the Table output you'd see in the CLI.

```ruby
# irb
# #:001 >

require "gem_dating"

dating = GemDating.from_string("rails")

more_dating = GemDating.from_file("path/to/Gemfile")


dating.to_a
# => [Gem::Specification.new do |s|
# s.name = "rails"
# s.version = Gem::Version.new("7.0.5")
# s.installed_by_version = Gem::Version.new("0") ...etc

dating.to_h
# => {"rails"=>{"name"=>"rails", "version"=>"7.0.5", "date"=>"2023-05-24"}}

more_dating.table_print
# =>
# NAME | VERSION | DATE
# ------------|---------|-----------
# rails | 7.0.5 | 2023-05-24
# ...etc
```



## Code of Conduct
Expand Down
7 changes: 7 additions & 0 deletions exe/gem_dating
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env ruby

$LOAD_PATH.unshift("#{__dir__}/../lib")

require "gem_dating"

exit GemDating::Cli.new(ARGV).run
1 change: 1 addition & 0 deletions lib/gem_dating.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
require_relative "gem_dating/input"
require_relative "gem_dating/rubygems"
require_relative "gem_dating/result"
require_relative "gem_dating/cli"

module GemDating
def self.from_string(s)
Expand Down
23 changes: 23 additions & 0 deletions lib/gem_dating/cli.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
module GemDating
class Cli
SUCCESS = 0
GENERAL_ERROR = 1

def initialize(argv)
@argv = argv
end

def run
if @argv.empty?
$stdout << "Usage: gem_dating [GEMFILE_FILEPATH]\n"
return GENERAL_ERROR
end

path = @argv.first

$stdout << GemDating.from_file(path).table_print << "\n"

SUCCESS
end
end
end
71 changes: 0 additions & 71 deletions test/Gemfile.example
Original file line number Diff line number Diff line change
Expand Up @@ -3,74 +3,3 @@ source "https://rubygems.org"
gem "rest-client"
gem "rails", '5.2.8.1'
gem 'graphql', '~> 1.10.5'
gem 'acts-as-taggable-on'
gem 'activerecord-import'
gem 'aws-sdk-s3', '~> 1.94.1'
gem 'bcrypt-ruby', require: 'bcrypt'
gem 'carrierwave', '~> 1.3.2'
gem 'dalli'
gem 'protected_attributes_continued'
gem 'resque'
gem 'doorkeeper'
gem "json"
gem 'mail', '~> 2.6.6'
gem 'mime-types', '1.25'
gem 'money', '~> 6.16.0'
gem 'nokogiri', '>= 1.6.0'
gem 'oauth2'
gem 'oj'
gem 'pg'
gem 'puma'
gem 'rest-client', '< 2.1'
gem 'rmagick', '> 2.13.2', require: false
gem 'stripe', git: 'https://github.com/stripe/stripe-ruby'
gem 'will_paginate'
gem 'rubyzip', '~> 1.3.0'
gem 'ruby-progressbar'
gem 'jwt'
gem 'lograge'
gem 'redis'
gem 'sprockets', '~> 3.7.2'
gem 'scientist'
gem 'jbuilder'

group :development do
gem 'dotenv'
gem 'foreman'
gem 'spring', require: false
end

group :development, :test, :selenium do
gem "brakeman", '>3', require: false
gem 'bundler-audit', '>0.3', require: false
gem 'bullet'
gem 'capybara'
gem 'chromedriver-helper'
gem 'css_parser', require: false
gem 'geckodriver-bin'
gem 'selenium-webdriver'
gem 'pry'
gem 'pry-byebug'
gem 'rack-test'
gem 'rack_session_access'
gem 'rspec-rails'
gem 'rspec-its'
gem 'rspec-collection_matchers'
gem 'webmock', require: false
gem "vcr"
gem 'xray', require: false
gem 'activerecord-tablefree'
gem 'shoulda-matchers', '~> 3.1', require: false
gem 'ruby-prof'
end

group :test do
gem 'database_cleaner', '~> 1.7.0'
gem 'db-query-matchers'
gem 'rails-controller-testing'
gem 'rspec-benchmark'
gem 'rspec-retry'
gem 'resque_spec'
gem 'factory_bot_rails', '~> 4.11.1'
gem 'rr', require: false
end
66 changes: 66 additions & 0 deletions test/cli_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
require "test_helper"
require "date"

class GemDating::CliTest < Minitest::Test
def setup
@spec1 = Gem::Specification.new do |s|
s.name = "banana-client"
s.version = "21.1.0"
s.date = DateTime.parse("1990-08-21")
end
@spec2 = Gem::Specification.new do |s|
s.name = "rails-on-rubies"
s.version = "70.0.5"
s.date = DateTime.parse("2123-05-24")
end
@spec3 = Gem::Specification.new do |s|
s.name = "giraffeql"
s.version = "0.0.2227"
s.date = DateTime.parse("2023-05-17")
end
end

def test_gemfile
exit_code = nil

Mocktail.replace(GemDating::Rubygems)
stubs { |m| GemDating::Rubygems.fetch(m.is_a(Array)) }.with { [@spec1, @spec2, @spec3] }

stdout, _stderr = capture_io do
exit_code = GemDating::Cli.new(["test/Gemfile.example"]).run
end

expected_out = <<~EXPECTED
NAME | VERSION | DATE
----------------|----------|-----------
banana-client | 21.1.0 | 1990-08-21
rails-on-rubies | 70.0.5 | 2123-05-24
giraffeql | 0.0.2227 | 2023-05-17
EXPECTED

assert_equal 0, exit_code
assert_equal expected_out, stdout
end

def test_no_args_prints_help
exit_code = nil

stdout, _stderr = capture_io do
exit_code = GemDating::Cli.new([]).run
end

expected_out =
<<~EXPECTED
Usage: gem_dating [GEMFILE_FILEPATH]
EXPECTED

assert_equal 1, exit_code
assert_equal expected_out, stdout
end

def test_bad_filepath
assert_raises Errno::ENOENT do
GemDating::Cli.new(["test/Gemfile.nope"]).run
end
end
end
10 changes: 9 additions & 1 deletion test/test_helper.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
$LOAD_PATH.unshift File.expand_path("../../lib", __FILE__)
require "gem_dating"

require "minitest/autorun"
require "mocktail"

class Minitest::Test
include Mocktail::DSL

def teardown
Mocktail.reset
end
end

0 comments on commit 6769d06

Please sign in to comment.