Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: 3.3
ruby-version: 3.4
bundler-cache: true

- name: Run tests
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish-gem.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: '3.3'
ruby-version: '3.4'
bundler-cache: true

- name: Build gem
Expand Down
1 change: 1 addition & 0 deletions .ruby-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.4.2
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

source 'https://rubygems.org'

gemspec
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
Utility which will output a table containing gem versions used across your projects.

[![Build & Test](https://github.com/FundingCircle/hellgrid/actions/workflows/build-and-test.yml/badge.svg)](https://github.com/FundingCircle/hellgrid/actions/workflows/build-and-test.yml)
[![Gem Version](https://badge.fury.io/rb/hellgrid.svg)](https://badge.fury.io/rb/hellgrid)

## Install

Expand Down
1 change: 1 addition & 0 deletions bin/hellgrid
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

require 'pathname'
# XXX: BUNDLE_GEMFILE should be provided because the internals of bundler require a 'Gemfile' or '.bundle' to
Expand Down
1 change: 1 addition & 0 deletions exe/hellgrid
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

require 'pathname'
# XXX: BUNDLE_GEMFILE should be provided because the internals of bundler require a 'Gemfile' or '.bundle' to
Expand Down
18 changes: 14 additions & 4 deletions hellgrid.gemspec
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

project_root = File.dirname(__FILE__)
lib = File.join(project_root, 'lib')

Expand All @@ -11,15 +13,23 @@ Gem::Specification.new do |s|
s.description = 'Display gem versions used across your projects in a table'
s.authors = ['Deyan Dobrinov', 'Aleksandar Ivanov']
s.email = ['engineering+hellgrid@fundingcircle.com']
s.files = Dir.chdir(project_root) { Dir['lib/**/*.rb'] + Dir['bin/*'] + Dir['exe/*'] + Dir['spec/**/*.rb'] + %w(Gemfile Gemfile.lock README.md hellgrid.gemspec) }
s.files = Dir.chdir(project_root) do
Dir['lib/**/*.rb'] +
Dir['bin/*'] +
Dir['exe/*'] +
Dir['spec/**/*.rb'] +
%w[Gemfile Gemfile.lock README.md hellgrid.gemspec]
end
s.bindir = 'exe'
s.executables = s.files.grep(/^exe\//) { |f| File.basename(f) }
s.test_files = s.files.grep(/^spec\//)
s.executables = s.files.grep(%r{^exe/}) { |f| File.basename(f) }
s.test_files = s.files.grep(%r{^spec/})
s.require_paths = ['lib']
s.homepage = 'https://github.com/FundingCircle/hellgrid'
s.license = 'BSD-3-Clause'

s.required_ruby_version = '>= 3.1.0'

s.add_runtime_dependency 'bundler', '>= 1.11.0', '< 3'

s.add_development_dependency 'rspec', '~> 3.8.0'
s.add_development_dependency 'rspec', '~> 3.13'
end
2 changes: 2 additions & 0 deletions lib/hellgrid.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'bundler'
require 'find'
require 'hellgrid/project'
Expand Down
6 changes: 4 additions & 2 deletions lib/hellgrid/cli.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Hellgrid
class CLI
def self.start(argv = ARGV)
Expand All @@ -11,8 +13,8 @@ def initialize(argv = ARGV)
attr_reader :argv

def start
recursive_search = !!(argv.delete('-r'))
transpose = !!(argv.delete('-t'))
recursive_search = !argv.delete('-r').nil?
transpose = !argv.delete('-t').nil?

folders = argv.empty? ? [Dir.pwd] : argv

Expand Down
8 changes: 5 additions & 3 deletions lib/hellgrid/matrix.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Hellgrid
class Matrix
attr_reader :projects
Expand All @@ -11,7 +13,7 @@ def add_project(project)
end

def projects_sorted_by_name
@projects.sort { |a,b| a.name <=> b.name }
@projects.sort { |a, b| a.name <=> b.name }
end

def project_names
Expand All @@ -36,12 +38,12 @@ def gems_by_usage
gem_usage = Hash.new(0)

projects.each do |project|
project.dependency_matrix.each do |gem, _|
project.dependency_matrix.each_key do |gem|
gem_usage[gem] += 1
end
end

gem_usage.sort_by {|key, value| [-value, key] }.to_h
gem_usage.sort_by { |key, value| [-value, key] }.to_h
end
end
end
6 changes: 4 additions & 2 deletions lib/hellgrid/project.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Hellgrid
class Project
attr_reader :path
Expand All @@ -8,11 +10,11 @@ def initialize(root, path)
end

def name
File.expand_path(path).gsub(File.expand_path(root) + '/', '')
File.expand_path(path).gsub("#{File.expand_path(root)}/", '')
end

def dependency_matrix
@dependency_matrix ||= specs.inject(Hash.new) { |h,spec| h.merge!(spec.name.to_s => spec.version.version) }
@dependency_matrix ||= specs.inject({}) { |h, spec| h.merge!(spec.name.to_s => spec.version.version) }
end

private
Expand Down
4 changes: 3 additions & 1 deletion lib/hellgrid/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Hellgrid
VERSION = '0.5.0'
VERSION = '0.6.0'
end
8 changes: 4 additions & 4 deletions lib/hellgrid/views/console.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Hellgrid
module Views
class Console
Expand All @@ -21,7 +23,7 @@ def render_as_string
string << row_as_string(row)
end

string.join("\n") + "\n"
"#{string.join("\n")}\n"
end

private
Expand All @@ -35,9 +37,7 @@ def column_widths

matrix.each do |row|
row.each_with_index do |value, col_i|
if value && (widths[col_i] < value.size)
widths[col_i] = value.size
end
widths[col_i] = value.size if value && (widths[col_i] < value.size)
end
end

Expand Down
139 changes: 84 additions & 55 deletions spec/hellgrid/matrix_spec.rb
Original file line number Diff line number Diff line change
@@ -1,81 +1,100 @@
# frozen_string_literal: true

require 'spec_helper'

describe Hellgrid::Matrix do
subject(:matrix) { described_class.new }
let(:project) { [] }

describe '#add_project' do
let(:project) { double(:project) }
def stub_project(name: 'foo', dependency_matrix: {})
instance_double(Hellgrid::Project, name:, dependency_matrix:)
end

describe '#add_project' do
it 'adds a project' do
expect do
matrix.add_project(project)
matrix.add_project(stub_project)
end.to change { matrix.projects.count }.by(1)
end
end

describe '#project_names' do
it 'returns project names' do
matrix.add_project(double(:project, name: 'foo'))
matrix.add_project(double(:project, name: 'bar'))
matrix.add_project(stub_project(name: 'foo'))
matrix.add_project(stub_project(name: 'bar'))

expect(matrix.project_names).to eq(['bar', 'foo'])
expect(matrix.project_names).to eq(%w[bar foo])
end
end

describe '#gem_names' do
it 'returns gem names' do
matrix.add_project(double(:project, dependency_matrix: {
'a' => '1.0.1',
'b' => '2.0.1',
'c' => '3.0.1'
}))

matrix.add_project(double(:project, dependency_matrix: {
'b' => '2.0.2',
'c' => '3.0.2',
'd' => '4.0.2'
}))

expect(matrix.gem_names).to eq(['a', 'b', 'c', 'd'])
matrix.add_project(
stub_project(
dependency_matrix: {
'a' => '1.0.1',
'b' => '2.0.1',
'c' => '3.0.1'
}
)
)

matrix.add_project(
stub_project(
dependency_matrix: {
'b' => '2.0.2',
'c' => '3.0.2',
'd' => '4.0.2'
}
)
)

expect(matrix.gem_names).to eq(%w[a b c d])
end
end

describe '#gems_by_usage' do
before do
matrix.add_project(double(:project, dependency_matrix: {
'a' => '1.0.1',
'b' => '2.0.1',
'c' => '3.0.1'
}))

matrix.add_project(double(:project, dependency_matrix: {
'b' => '2.0.2',
'c' => '3.0.2',
'd' => '4.0.2'
}))
matrix.add_project(
stub_project(
dependency_matrix: {
'a' => '1.0.1',
'b' => '2.0.1',
'c' => '3.0.1'
}
)
)

matrix.add_project(
stub_project(
dependency_matrix: {
'b' => '2.0.2',
'c' => '3.0.2',
'd' => '4.0.2'
}
)
)
end

it 'returns an array' do
expect(matrix.gems_by_usage).to be_a(Hash)
end

it 'returns ordered ' do
it 'returns ordered' do
expected_result = {
"b"=>2,
"c"=>2,
"a"=>1,
"d"=>1
'b' => 2,
'c' => 2,
'a' => 1,
'd' => 1
}

expect(matrix.gems_by_usage).to eq(expected_result)
end
end

describe '#projects_sorted_by_name' do
let(:project_a) { double(:project, name: 'a') }
let(:project_b) { double(:project, name: 'b') }
let(:project_c) { double(:project, name: 'c') }
let(:project_a) { stub_project(name: 'a') }
let(:project_b) { stub_project(name: 'b') }
let(:project_c) { stub_project(name: 'c') }

before do
matrix.add_project(project_b)
Expand All @@ -92,26 +111,36 @@

describe '#sorted_by_most_used' do
before do
matrix.add_project(double(:project, name: 'foo', dependency_matrix: {
'a' => '1.0.1',
'b' => '2.0.1',
'c' => '3.0.1'
}))

matrix.add_project(double(:project, name: 'bar', dependency_matrix: {
'b' => '2.0.2',
'c' => '3.0.2',
'd' => '4.0.2'
}))
matrix.add_project(
stub_project(
name: 'foo',
dependency_matrix: {
'a' => '1.0.1',
'b' => '2.0.1',
'c' => '3.0.1'
}
)
)

matrix.add_project(
stub_project(
name: 'bar',
dependency_matrix: {
'b' => '2.0.2',
'c' => '3.0.2',
'd' => '4.0.2'
}
)
)
end

it 'returns matrix' do
expected_result = [
[ nil, 'bar', 'foo' ],
[ 'b', '2.0.2', '2.0.1' ],
[ 'c', '3.0.2', '3.0.1' ],
[ 'a', nil, '1.0.1' ],
[ 'd', '4.0.2', nil ]
[nil, 'bar', 'foo'],
['b', '2.0.2', '2.0.1'],
['c', '3.0.2', '3.0.1'],
['a', nil, '1.0.1'],
['d', '4.0.2', nil]
]

expect(matrix.sorted_by_most_used).to eq(expected_result)
Expand Down
Loading