Skip to content

Commit

Permalink
Merge pull request #36 from FundingCircle/matrix-transpose
Browse files Browse the repository at this point in the history
Add a way to transpose the matrix
  • Loading branch information
bliof-fc committed May 7, 2024
2 parents ed929b1 + 5e04ed4 commit 8b8fba3
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 4 deletions.
20 changes: 18 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@ gem install hellgrid
Let say that you have a directory `/path/to/root/dir` somewhere in which the Ruby projects `foo` and `bar` could be found.

Executing:

```bash
hellgrid /path/to/root/dir
```

To search recursively (should you have nested projects), use the `-r ` flag:
```

```bash
hellgrid -r /path/to/root/dir
```

Expand All @@ -35,7 +37,21 @@ Should result in:
rspec-mocks | 2.0.0 | 3.0.4
rake | 10.0.0 | 11.1.0
rspec-support | x | 3.0.4
hellgrid | x | x
```

To have the gems as columns, use the `-t` flag:

```bash
hellgrid -t /path/to/root/dir
```

Should result in:

```bash
x | diff-lcs | rake | rspec | rspec-core | rspec-expectations | rspec-mocks | rspec-support
--------+----------+--------+-------+------------+--------------------+-------------+---------------
bar | 1.2.5 | 10.0.0 | 2.0.0 | 2.0.0 | 2.0.0 | 2.0.0 | x
foo | 1.2.5 | 11.1.0 | 3.0.0 | 3.0.4 | 3.0.4 | 3.0.4 | 3.0.4
```

## License
Expand Down
7 changes: 6 additions & 1 deletion lib/hellgrid/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ def initialize(argv = ARGV)

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

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

folders.each do |folder|
Expand All @@ -24,7 +26,10 @@ def start
end
end

view = Hellgrid::Views::Console.new(matrix.sorted_by_most_used)
data = matrix.sorted_by_most_used
data = data.transpose if transpose

view = Hellgrid::Views::Console.new(data)

view.render
end
Expand Down
2 changes: 1 addition & 1 deletion lib/hellgrid/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Hellgrid
VERSION = '0.4.0'
VERSION = '0.5.0'
end
15 changes: 15 additions & 0 deletions spec/hellgrid_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -132,4 +132,19 @@ def with_unbundled_env(&block)
end
end
end

context 'when passing -t' do
it 'transposes the result and the project names on the left' do
expected_result = <<-TABLE
x | diff-lcs | rake | rspec | rspec-core | rspec-expectations | rspec-mocks | rspec-support
--------+----------+--------+-------+------------+--------------------+-------------+---------------
bar | 1.2.5 | 10.0.0 | 2.0.0 | 2.0.0 | 2.0.0 | 2.0.0 | x
in/foo | 1.2.5 | 11.1.0 | 3.0.0 | 3.0.4 | 3.0.4 | 3.0.4 | 3.0.4
TABLE

with_unbundled_env do
expect(`cd #{PROJECT_ROOT}/spec/tmp && #{PROJECT_ROOT}/bin/hellgrid -t`).to eq(expected_result)
end
end
end
end

0 comments on commit 8b8fba3

Please sign in to comment.