this_is_ruby 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0a2047298c7f0c4729968ed6827707200b80ad5810ccde2c5fcd6fb009d4b662
4
- data.tar.gz: 541e8c560fdb8441a4aa4ec0f040827a10454feb8bd467cad44840a614a05455
3
+ metadata.gz: 7cb3f275dd3475b96089c47a5dbef85a28240daae468e08fbac08e283afd6c96
4
+ data.tar.gz: 5ac450e2705dafa4176d89960356825d47511faeaf79e0f6420022bf18b403e3
5
5
  SHA512:
6
- metadata.gz: f09cc8394377d79592a9e8e845a6da04c1dd4fcfa113ebebcf0460af1d8cc3b8c240f8e944048b9a471790d926e1d49123533546aaa093b111598255173de0f4
7
- data.tar.gz: f4eeae23cde25381e1fd4132f6904e7c4f5a07a1980a8e7855e115d5532ad8c84fb6b25af916264b786e2ec64f2e93f1679597edddfe70c7c7251aea287f35c2
6
+ metadata.gz: 275d332b9ff9b7b8039a58c77875f539d9e9769322df96b7cddfe1bb7e640ee0074312641e1fd0855b95b331563a71115c5bce3d8b4b51bb9bebb8326c1f4b89
7
+ data.tar.gz: fa0bbf5a22382f4da346e9c5725cd982635a9ab7dd2130efb19a98465b0a34f7eb20a0537e56a50d57d5a4ad86c9164c4335d7ba0600e611f663ee5f99846c04
data/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.1.1
4
+
5
+ - The "now" column no longer counts files that are already out of GitHub's
6
+ language bar. It asks `git check-attr`, so Rails' own `db/schema.rb` line and
7
+ anything written by hand are honoured, and it subtracts only what this run
8
+ claims, so re-running on a repository already converted still shows the
9
+ contrast rather than reporting that nothing would change.
10
+
3
11
  ## 0.1.0
4
12
 
5
13
  Initial release.
@@ -8,18 +16,8 @@ Initial release.
8
16
  Webpacker and Vite builds, SimpleCov reports, SQL structure dumps and
9
17
  shadcn/ui components.
10
18
  - Writes a managed block in `.gitattributes`, leaving the rest of the file
11
- untouched, and stays quiet about anything already declared there.
12
- - `plan`, `apply` and `check` commands; `--all-frontend` opt-in.
13
-
14
- ## Unreleased
15
-
16
- - Exit 1 on an unknown command or option instead of 0, so a typo in a CI step
17
- fails rather than silently skipping `check`.
18
- - Leave a path alone when its Linguist attribute is already decided, including
19
- when it was explicitly unset (`-linguist-generated`) or made unspecified
20
- (`!linguist-generated`). Writing our line after such a declaration reversed
21
- it, because the last match wins.
22
- - Rewrite the managed block where it already sits, so content below it stays
23
- below it.
24
- - Read `git rev-parse` from stdout alone: with `GIT_TRACE` set, or on any git
25
- warning, the merged stream became part of the repository root.
19
+ untouched, and stays quiet about anything already decided there, including an
20
+ attribute the owner explicitly unset.
21
+ - Rewrites the block where it sits, so content below it stays below it.
22
+ - `plan`, `apply` and `check` commands; `--all-frontend` opt-in, which uses
23
+ `linguist-vendored` so diffs keep working.
data/README.md CHANGED
@@ -1,5 +1,8 @@
1
1
  # this_is_ruby
2
2
 
3
+ [![Gem](https://img.shields.io/gem/v/this_is_ruby)](https://rubygems.org/gems/this_is_ruby)
4
+ [![CI](https://github.com/evilmartians/this_is_ruby/actions/workflows/ci.yml/badge.svg)](https://github.com/evilmartians/this_is_ruby/actions/workflows/ci.yml)
5
+
3
6
  GitHub decides a repository's language by counting bytes. Ruby code can often be outnumbered by sheer volume of JS/TS/HTML boilerplate. So GitHub labels the repo HTML or TypeScript.
4
7
 
5
8
  This gem gives you controls.
@@ -12,6 +15,9 @@ group :development do
12
15
  end
13
16
  ```
14
17
 
18
+ Or `gem install this_is_ruby` to run it against any repository without adding
19
+ it to a project.
20
+
15
21
  ## Use
16
22
 
17
23
  ```console
@@ -65,8 +65,12 @@ module ThisIsRuby
65
65
  @claimed_paths ||= emissions.flat_map(&:paths).to_set
66
66
  end
67
67
 
68
- def before = @before ||= LanguageEstimate.of(repo)
68
+ # The bar without our block: what GitHub reports today, minus the paths this
69
+ # run is claiming. Asking git means Rails' own `db/schema.rb` line and
70
+ # anything hand-written are honoured, while re-running on a repository we
71
+ # already converted still shows the contrast rather than "nothing changes".
72
+ def before = @before ||= LanguageEstimate.of(repo, excluding: repo.already_excluded - claimed_paths)
69
73
 
70
- def after = @after ||= LanguageEstimate.of(repo, excluding: claimed_paths)
74
+ def after = @after ||= LanguageEstimate.of(repo, excluding: repo.already_excluded | claimed_paths)
71
75
  end
72
76
  end
@@ -17,6 +17,9 @@ module ThisIsRuby
17
17
  # markers we check for all sit in the first few lines.
18
18
  PEEK_BYTES = 4096
19
19
 
20
+ # The attributes that take a file out of GitHub's language statistics.
21
+ LINGUIST_EXCLUSIONS = %w[linguist-generated linguist-vendored linguist-documentation].freeze
22
+
20
23
  attr_reader :root
21
24
 
22
25
  def self.at(path)
@@ -55,6 +58,17 @@ module ThisIsRuby
55
58
  full.open("rb") { |io| io.read(PEEK_BYTES) }
56
59
  end
57
60
 
61
+ # Paths git already reports as excluded from Linguist's counts, whoever
62
+ # declared them: our own block, the lines Rails generates, or something
63
+ # written by hand. Resolving the patterns ourselves would mean
64
+ # reimplementing gitignore matching, so ask git, which owns the answer.
65
+ def already_excluded
66
+ @already_excluded ||= begin
67
+ paths = tracked
68
+ paths.empty? ? Set.new : Set.new(check_attr(paths))
69
+ end
70
+ end
71
+
58
72
  def size(path)
59
73
  full = root.join(path)
60
74
  full.file? ? full.size : 0
@@ -62,6 +76,18 @@ module ThisIsRuby
62
76
 
63
77
  private
64
78
 
79
+ # `check-attr --stdin -z` reads NUL-separated paths and answers with
80
+ # NUL-separated (path, attribute, value) triples.
81
+ def check_attr(paths)
82
+ out, _err, status = Open3.capture3(
83
+ "git", "-C", root.to_s, "check-attr", "--stdin", "-z", *LINGUIST_EXCLUSIONS,
84
+ stdin_data: paths.join("\0")
85
+ )
86
+ return [] unless status.success?
87
+
88
+ out.split("\0").each_slice(3).filter_map { |path, _attribute, value| path if value == "set" }
89
+ end
90
+
65
91
  def tracked_set
66
92
  @tracked_set ||= tracked.to_set
67
93
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ThisIsRuby
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.1"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: this_is_ruby
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
  - Irina Nazarova