is_this_used 0.1.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 6230a093e9c43e76f49f6029109cb16fa0287deb22285e1f01b0d0732fe076dc
4
+ data.tar.gz: 3e8d0cd036daec5d0feb1a0d17fe94f0a0e1509f24962145ca01dedded5e5ea1
5
+ SHA512:
6
+ metadata.gz: ccd634c5a840b1c0aa82ac266dda18e6da727e4b65f31829b81ca549eb792e0ae866aaf91eca93d45107149b8b28f8d760c900e95eb174101f5a1f2a8a4e3e80
7
+ data.tar.gz: 5e1b79de772247fefc0304d75346f507d9de0f88533808a715f3fb2f38057c6703dff0b28ecf83bedfb253b3fb96bd6384ccb0805b2c1d8bb46f2999de661dba
data/.gitignore ADDED
@@ -0,0 +1,19 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
12
+ .idea
13
+
14
+ Gemfile.lock
15
+
16
+ spec/dummy/
17
+ spec/dummy_app/db/schema.rb
18
+ spec/dummy_app/log/*
19
+ spec/dummy_app/tmp/*
data/.prettierrc ADDED
@@ -0,0 +1,5 @@
1
+ {
2
+ "extends": [
3
+ "plugin:@prettier/plugin-ruby"
4
+ ]
5
+ }
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.6.3
7
+ before_install: gem install bundler -v 1.17.2
data/Appraisals ADDED
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Specify here only version constraints that differ from
4
+ # `paper_trail.gemspec`.
5
+ #
6
+ # > The dependencies in your Appraisals file are combined with dependencies in
7
+ # > your Gemfile, so you don't need to repeat anything that's the same for each
8
+ # > appraisal. If something is specified in both the Gemfile and an appraisal,
9
+ # > the version from the appraisal takes precedence.
10
+ # > https://github.com/thoughtbot/appraisal
11
+ #
12
+ #
13
+ appraise "rails-5.2" do
14
+ gem "rails", "~> 5.2.4"
15
+ end
16
+
17
+ appraise "rails-6.0" do
18
+ gem "rails", "~> 6.0.3"
19
+ end
20
+
21
+ # appraise "rails-6.1" do
22
+ # gem "rails", "~> 6.1.0"
23
+ # gem "rails-controller-testing", "~> 1.0.5"
24
+ # end
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in is_this_used.gemspec
6
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2022 Doug Hughes
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,75 @@
1
+ # IsThisUsed
2
+
3
+ Do you ever ask yourself, "Is this method even being used?!" Does your app use ActiveRecord? If so, this gem may be
4
+ useful to you!
5
+
6
+ Large applications can accrue cruft; old methods that might once have been important, but are now unused. The thing is,
7
+ software is _complex_. If the method in question was a part of a larger feature that has changed over time, or possibly
8
+ been removed or disabled, it can be really difficult to tell if it's being used at all. It can be even worse that than.
9
+ The method could be _tested_. 😨 That's bad because now you can tell if you break it and you'll need to maintain it, but
10
+ you have no idea if there's any value in the time and effort to do so.
11
+
12
+ The gem uses ActiveRecord to write to your database, so that's a dependency. Basically, this is really only useful for
13
+ Rails applications at this point. Also, as of now, only MySQL is supported. Other DBs could be added in the future.
14
+
15
+ ## Installation
16
+
17
+ Add this line to your application's Gemfile:
18
+
19
+ ```ruby
20
+ gem 'is_this_used'
21
+ ```
22
+
23
+ And then execute:
24
+
25
+ ```
26
+ bundle
27
+ ```
28
+
29
+ Or install it yourself as:
30
+
31
+ ```
32
+ gem install is_this_used
33
+ ```
34
+
35
+ You'll need to generate and run the migrations to add the required tables to your database:
36
+
37
+ ```bash
38
+ bundle exec rails generate is_this_used:migration
39
+ bundle exec rails db:migrate
40
+ ```
41
+
42
+ This will create two tables, `potential_crufts`, which is used to collect information on the methods you're
43
+ investigating, and `potential_cruft_stacks` which contains unique stack traces for when invocations of that method
44
+ actually occur.
45
+
46
+ ## Usage
47
+
48
+ TODO
49
+
50
+ ## Development
51
+
52
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can
53
+ also run `bin/console` for an interactive prompt that will allow you to experiment.
54
+
55
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the
56
+ version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version,
57
+ push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
58
+
59
+ ## Contributing
60
+
61
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/is_this_used.
62
+
63
+ ## License
64
+
65
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
66
+
67
+ # To run tests
68
+
69
+ ## Rails 5.2
70
+
71
+ bundle exec appraisal rails-5.2 rake
72
+
73
+ ## Rails 6.0
74
+
75
+ bundle exec appraisal rails-6.0 rake
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "is_this_used"
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
@@ -0,0 +1,8 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rails", "~> 5.2.4"
6
+ # gem "rails-controller-testing", "~> 1.0.2"
7
+
8
+ gemspec path: "../"
@@ -0,0 +1,206 @@
1
+ PATH
2
+ remote: ..
3
+ specs:
4
+ is_this_used (0.1.0)
5
+ activerecord (>= 5.2)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ actioncable (5.2.4.6)
11
+ actionpack (= 5.2.4.6)
12
+ nio4r (~> 2.0)
13
+ websocket-driver (>= 0.6.1)
14
+ actionmailer (5.2.4.6)
15
+ actionpack (= 5.2.4.6)
16
+ actionview (= 5.2.4.6)
17
+ activejob (= 5.2.4.6)
18
+ mail (~> 2.5, >= 2.5.4)
19
+ rails-dom-testing (~> 2.0)
20
+ actionpack (5.2.4.6)
21
+ actionview (= 5.2.4.6)
22
+ activesupport (= 5.2.4.6)
23
+ rack (~> 2.0, >= 2.0.8)
24
+ rack-test (>= 0.6.3)
25
+ rails-dom-testing (~> 2.0)
26
+ rails-html-sanitizer (~> 1.0, >= 1.0.2)
27
+ actionview (5.2.4.6)
28
+ activesupport (= 5.2.4.6)
29
+ builder (~> 3.1)
30
+ erubi (~> 1.4)
31
+ rails-dom-testing (~> 2.0)
32
+ rails-html-sanitizer (~> 1.0, >= 1.0.3)
33
+ activejob (5.2.4.6)
34
+ activesupport (= 5.2.4.6)
35
+ globalid (>= 0.3.6)
36
+ activemodel (5.2.4.6)
37
+ activesupport (= 5.2.4.6)
38
+ activerecord (5.2.4.6)
39
+ activemodel (= 5.2.4.6)
40
+ activesupport (= 5.2.4.6)
41
+ arel (>= 9.0)
42
+ activestorage (5.2.4.6)
43
+ actionpack (= 5.2.4.6)
44
+ activerecord (= 5.2.4.6)
45
+ marcel (~> 0.3.1)
46
+ activesupport (5.2.4.6)
47
+ concurrent-ruby (~> 1.0, >= 1.0.2)
48
+ i18n (>= 0.7, < 2)
49
+ minitest (~> 5.1)
50
+ tzinfo (~> 1.1)
51
+ appraisal (2.4.1)
52
+ bundler
53
+ rake
54
+ thor (>= 0.14.0)
55
+ arel (9.0.0)
56
+ ast (2.4.2)
57
+ builder (3.2.4)
58
+ byebug (11.1.3)
59
+ coderay (1.1.3)
60
+ concurrent-ruby (1.1.9)
61
+ crass (1.0.6)
62
+ diff-lcs (1.5.0)
63
+ erubi (1.10.0)
64
+ generator_spec (0.9.4)
65
+ activesupport (>= 3.0.0)
66
+ railties (>= 3.0.0)
67
+ globalid (1.0.0)
68
+ activesupport (>= 5.0)
69
+ i18n (1.8.11)
70
+ concurrent-ruby (~> 1.0)
71
+ loofah (2.13.0)
72
+ crass (~> 1.0.2)
73
+ nokogiri (>= 1.5.9)
74
+ mail (2.7.1)
75
+ mini_mime (>= 0.1.1)
76
+ marcel (0.3.3)
77
+ mimemagic (~> 0.3.2)
78
+ method_source (1.0.0)
79
+ mimemagic (0.3.10)
80
+ nokogiri (~> 1)
81
+ rake
82
+ mini_mime (1.1.2)
83
+ minitest (5.15.0)
84
+ mysql2 (0.5.3)
85
+ nio4r (2.5.8)
86
+ nokogiri (1.13.1-x86_64-darwin)
87
+ racc (~> 1.4)
88
+ parallel (1.21.0)
89
+ parser (3.1.0.0)
90
+ ast (~> 2.4.1)
91
+ pry (0.13.1)
92
+ coderay (~> 1.1)
93
+ method_source (~> 1.0)
94
+ pry-byebug (3.9.0)
95
+ byebug (~> 11.0)
96
+ pry (~> 0.13.0)
97
+ racc (1.6.0)
98
+ rack (2.2.3)
99
+ rack-test (1.1.0)
100
+ rack (>= 1.0, < 3)
101
+ rails (5.2.4.6)
102
+ actioncable (= 5.2.4.6)
103
+ actionmailer (= 5.2.4.6)
104
+ actionpack (= 5.2.4.6)
105
+ actionview (= 5.2.4.6)
106
+ activejob (= 5.2.4.6)
107
+ activemodel (= 5.2.4.6)
108
+ activerecord (= 5.2.4.6)
109
+ activestorage (= 5.2.4.6)
110
+ activesupport (= 5.2.4.6)
111
+ bundler (>= 1.3.0)
112
+ railties (= 5.2.4.6)
113
+ sprockets-rails (>= 2.0.0)
114
+ rails-dom-testing (2.0.3)
115
+ activesupport (>= 4.2.0)
116
+ nokogiri (>= 1.6)
117
+ rails-html-sanitizer (1.4.2)
118
+ loofah (~> 2.3)
119
+ railties (5.2.4.6)
120
+ actionpack (= 5.2.4.6)
121
+ activesupport (= 5.2.4.6)
122
+ method_source
123
+ rake (>= 0.8.7)
124
+ thor (>= 0.19.0, < 2.0)
125
+ rainbow (3.1.1)
126
+ rake (10.5.0)
127
+ regexp_parser (2.2.0)
128
+ rexml (3.2.5)
129
+ rspec (3.10.0)
130
+ rspec-core (~> 3.10.0)
131
+ rspec-expectations (~> 3.10.0)
132
+ rspec-mocks (~> 3.10.0)
133
+ rspec-core (3.10.1)
134
+ rspec-support (~> 3.10.0)
135
+ rspec-expectations (3.10.2)
136
+ diff-lcs (>= 1.2.0, < 2.0)
137
+ rspec-support (~> 3.10.0)
138
+ rspec-mocks (3.10.2)
139
+ diff-lcs (>= 1.2.0, < 2.0)
140
+ rspec-support (~> 3.10.0)
141
+ rspec-rails (5.0.2)
142
+ actionpack (>= 5.2)
143
+ activesupport (>= 5.2)
144
+ railties (>= 5.2)
145
+ rspec-core (~> 3.10)
146
+ rspec-expectations (~> 3.10)
147
+ rspec-mocks (~> 3.10)
148
+ rspec-support (~> 3.10)
149
+ rspec-support (3.10.3)
150
+ rubocop (1.22.3)
151
+ parallel (~> 1.10)
152
+ parser (>= 3.0.0.0)
153
+ rainbow (>= 2.2.2, < 4.0)
154
+ regexp_parser (>= 1.8, < 3.0)
155
+ rexml
156
+ rubocop-ast (>= 1.12.0, < 2.0)
157
+ ruby-progressbar (~> 1.7)
158
+ unicode-display_width (>= 1.4.0, < 3.0)
159
+ rubocop-ast (1.15.1)
160
+ parser (>= 3.0.1.1)
161
+ rubocop-rails (2.12.4)
162
+ activesupport (>= 4.2.0)
163
+ rack (>= 1.1)
164
+ rubocop (>= 1.7.0, < 2.0)
165
+ rubocop-rake (0.6.0)
166
+ rubocop (~> 1.0)
167
+ rubocop-rspec (2.5.0)
168
+ rubocop (~> 1.19)
169
+ ruby-progressbar (1.11.0)
170
+ sprockets (4.0.2)
171
+ concurrent-ruby (~> 1.0)
172
+ rack (> 1, < 3)
173
+ sprockets-rails (3.4.2)
174
+ actionpack (>= 5.2)
175
+ activesupport (>= 5.2)
176
+ sprockets (>= 3.0.0)
177
+ thor (1.2.1)
178
+ thread_safe (0.3.6)
179
+ tzinfo (1.2.9)
180
+ thread_safe (~> 0.1)
181
+ unicode-display_width (2.1.0)
182
+ websocket-driver (0.7.5)
183
+ websocket-extensions (>= 0.1.0)
184
+ websocket-extensions (0.1.5)
185
+
186
+ PLATFORMS
187
+ ruby
188
+
189
+ DEPENDENCIES
190
+ appraisal (~> 2.4.1)
191
+ bundler (~> 1.17)
192
+ generator_spec (~> 0.9.4)
193
+ is_this_used!
194
+ mysql2 (~> 0.5.3)
195
+ pry-byebug (~> 3.9)
196
+ rails (~> 5.2.4)
197
+ rake (~> 10.0)
198
+ rspec (~> 3.0)
199
+ rspec-rails (~> 5.0.2)
200
+ rubocop (~> 1.22.2)
201
+ rubocop-rails (~> 2.12.4)
202
+ rubocop-rake (~> 0.6.0)
203
+ rubocop-rspec (~> 2.5.0)
204
+
205
+ BUNDLED WITH
206
+ 1.17.2
@@ -0,0 +1,8 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rails", "~> 6.0.3"
6
+ # gem "rails-controller-testing", "~> 1.0.3"
7
+
8
+ gemspec path: "../"
@@ -0,0 +1,218 @@
1
+ PATH
2
+ remote: ..
3
+ specs:
4
+ is_this_used (0.1.0)
5
+ activerecord (>= 5.2)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ actioncable (6.0.4.4)
11
+ actionpack (= 6.0.4.4)
12
+ nio4r (~> 2.0)
13
+ websocket-driver (>= 0.6.1)
14
+ actionmailbox (6.0.4.4)
15
+ actionpack (= 6.0.4.4)
16
+ activejob (= 6.0.4.4)
17
+ activerecord (= 6.0.4.4)
18
+ activestorage (= 6.0.4.4)
19
+ activesupport (= 6.0.4.4)
20
+ mail (>= 2.7.1)
21
+ actionmailer (6.0.4.4)
22
+ actionpack (= 6.0.4.4)
23
+ actionview (= 6.0.4.4)
24
+ activejob (= 6.0.4.4)
25
+ mail (~> 2.5, >= 2.5.4)
26
+ rails-dom-testing (~> 2.0)
27
+ actionpack (6.0.4.4)
28
+ actionview (= 6.0.4.4)
29
+ activesupport (= 6.0.4.4)
30
+ rack (~> 2.0, >= 2.0.8)
31
+ rack-test (>= 0.6.3)
32
+ rails-dom-testing (~> 2.0)
33
+ rails-html-sanitizer (~> 1.0, >= 1.2.0)
34
+ actiontext (6.0.4.4)
35
+ actionpack (= 6.0.4.4)
36
+ activerecord (= 6.0.4.4)
37
+ activestorage (= 6.0.4.4)
38
+ activesupport (= 6.0.4.4)
39
+ nokogiri (>= 1.8.5)
40
+ actionview (6.0.4.4)
41
+ activesupport (= 6.0.4.4)
42
+ builder (~> 3.1)
43
+ erubi (~> 1.4)
44
+ rails-dom-testing (~> 2.0)
45
+ rails-html-sanitizer (~> 1.1, >= 1.2.0)
46
+ activejob (6.0.4.4)
47
+ activesupport (= 6.0.4.4)
48
+ globalid (>= 0.3.6)
49
+ activemodel (6.0.4.4)
50
+ activesupport (= 6.0.4.4)
51
+ activerecord (6.0.4.4)
52
+ activemodel (= 6.0.4.4)
53
+ activesupport (= 6.0.4.4)
54
+ activestorage (6.0.4.4)
55
+ actionpack (= 6.0.4.4)
56
+ activejob (= 6.0.4.4)
57
+ activerecord (= 6.0.4.4)
58
+ marcel (~> 1.0.0)
59
+ activesupport (6.0.4.4)
60
+ concurrent-ruby (~> 1.0, >= 1.0.2)
61
+ i18n (>= 0.7, < 2)
62
+ minitest (~> 5.1)
63
+ tzinfo (~> 1.1)
64
+ zeitwerk (~> 2.2, >= 2.2.2)
65
+ appraisal (2.4.1)
66
+ bundler
67
+ rake
68
+ thor (>= 0.14.0)
69
+ ast (2.4.2)
70
+ builder (3.2.4)
71
+ byebug (11.1.3)
72
+ coderay (1.1.3)
73
+ concurrent-ruby (1.1.9)
74
+ crass (1.0.6)
75
+ diff-lcs (1.5.0)
76
+ erubi (1.10.0)
77
+ generator_spec (0.9.4)
78
+ activesupport (>= 3.0.0)
79
+ railties (>= 3.0.0)
80
+ globalid (1.0.0)
81
+ activesupport (>= 5.0)
82
+ i18n (1.8.11)
83
+ concurrent-ruby (~> 1.0)
84
+ loofah (2.13.0)
85
+ crass (~> 1.0.2)
86
+ nokogiri (>= 1.5.9)
87
+ mail (2.7.1)
88
+ mini_mime (>= 0.1.1)
89
+ marcel (1.0.2)
90
+ method_source (1.0.0)
91
+ mini_mime (1.1.2)
92
+ minitest (5.15.0)
93
+ mysql2 (0.5.3)
94
+ nio4r (2.5.8)
95
+ nokogiri (1.13.1-x86_64-darwin)
96
+ racc (~> 1.4)
97
+ parallel (1.21.0)
98
+ parser (3.1.0.0)
99
+ ast (~> 2.4.1)
100
+ pry (0.13.1)
101
+ coderay (~> 1.1)
102
+ method_source (~> 1.0)
103
+ pry-byebug (3.9.0)
104
+ byebug (~> 11.0)
105
+ pry (~> 0.13.0)
106
+ racc (1.6.0)
107
+ rack (2.2.3)
108
+ rack-test (1.1.0)
109
+ rack (>= 1.0, < 3)
110
+ rails (6.0.4.4)
111
+ actioncable (= 6.0.4.4)
112
+ actionmailbox (= 6.0.4.4)
113
+ actionmailer (= 6.0.4.4)
114
+ actionpack (= 6.0.4.4)
115
+ actiontext (= 6.0.4.4)
116
+ actionview (= 6.0.4.4)
117
+ activejob (= 6.0.4.4)
118
+ activemodel (= 6.0.4.4)
119
+ activerecord (= 6.0.4.4)
120
+ activestorage (= 6.0.4.4)
121
+ activesupport (= 6.0.4.4)
122
+ bundler (>= 1.3.0)
123
+ railties (= 6.0.4.4)
124
+ sprockets-rails (>= 2.0.0)
125
+ rails-dom-testing (2.0.3)
126
+ activesupport (>= 4.2.0)
127
+ nokogiri (>= 1.6)
128
+ rails-html-sanitizer (1.4.2)
129
+ loofah (~> 2.3)
130
+ railties (6.0.4.4)
131
+ actionpack (= 6.0.4.4)
132
+ activesupport (= 6.0.4.4)
133
+ method_source
134
+ rake (>= 0.8.7)
135
+ thor (>= 0.20.3, < 2.0)
136
+ rainbow (3.1.1)
137
+ rake (10.5.0)
138
+ regexp_parser (2.2.0)
139
+ rexml (3.2.5)
140
+ rspec (3.10.0)
141
+ rspec-core (~> 3.10.0)
142
+ rspec-expectations (~> 3.10.0)
143
+ rspec-mocks (~> 3.10.0)
144
+ rspec-core (3.10.1)
145
+ rspec-support (~> 3.10.0)
146
+ rspec-expectations (3.10.2)
147
+ diff-lcs (>= 1.2.0, < 2.0)
148
+ rspec-support (~> 3.10.0)
149
+ rspec-mocks (3.10.2)
150
+ diff-lcs (>= 1.2.0, < 2.0)
151
+ rspec-support (~> 3.10.0)
152
+ rspec-rails (5.0.2)
153
+ actionpack (>= 5.2)
154
+ activesupport (>= 5.2)
155
+ railties (>= 5.2)
156
+ rspec-core (~> 3.10)
157
+ rspec-expectations (~> 3.10)
158
+ rspec-mocks (~> 3.10)
159
+ rspec-support (~> 3.10)
160
+ rspec-support (3.10.3)
161
+ rubocop (1.22.3)
162
+ parallel (~> 1.10)
163
+ parser (>= 3.0.0.0)
164
+ rainbow (>= 2.2.2, < 4.0)
165
+ regexp_parser (>= 1.8, < 3.0)
166
+ rexml
167
+ rubocop-ast (>= 1.12.0, < 2.0)
168
+ ruby-progressbar (~> 1.7)
169
+ unicode-display_width (>= 1.4.0, < 3.0)
170
+ rubocop-ast (1.15.1)
171
+ parser (>= 3.0.1.1)
172
+ rubocop-rails (2.12.4)
173
+ activesupport (>= 4.2.0)
174
+ rack (>= 1.1)
175
+ rubocop (>= 1.7.0, < 2.0)
176
+ rubocop-rake (0.6.0)
177
+ rubocop (~> 1.0)
178
+ rubocop-rspec (2.5.0)
179
+ rubocop (~> 1.19)
180
+ ruby-progressbar (1.11.0)
181
+ sprockets (4.0.2)
182
+ concurrent-ruby (~> 1.0)
183
+ rack (> 1, < 3)
184
+ sprockets-rails (3.4.2)
185
+ actionpack (>= 5.2)
186
+ activesupport (>= 5.2)
187
+ sprockets (>= 3.0.0)
188
+ thor (1.2.1)
189
+ thread_safe (0.3.6)
190
+ tzinfo (1.2.9)
191
+ thread_safe (~> 0.1)
192
+ unicode-display_width (2.1.0)
193
+ websocket-driver (0.7.5)
194
+ websocket-extensions (>= 0.1.0)
195
+ websocket-extensions (0.1.5)
196
+ zeitwerk (2.5.3)
197
+
198
+ PLATFORMS
199
+ ruby
200
+
201
+ DEPENDENCIES
202
+ appraisal (~> 2.4.1)
203
+ bundler (~> 1.17)
204
+ generator_spec (~> 0.9.4)
205
+ is_this_used!
206
+ mysql2 (~> 0.5.3)
207
+ pry-byebug (~> 3.9)
208
+ rails (~> 6.0.3)
209
+ rake (~> 10.0)
210
+ rspec (~> 3.0)
211
+ rspec-rails (~> 5.0.2)
212
+ rubocop (~> 1.22.2)
213
+ rubocop-rails (~> 2.12.4)
214
+ rubocop-rake (~> 0.6.0)
215
+ rubocop-rspec (~> 2.5.0)
216
+
217
+ BUNDLED WITH
218
+ 1.17.2
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'is_this_used/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'is_this_used'
9
+ spec.version = IsThisUsed::VERSION
10
+ spec.authors = ['Doug Hughes']
11
+ spec.email = ['doug@doughughes.net']
12
+
13
+ spec.summary = 'Provides a system to track method usage somewhat unobtrusively.'
14
+ spec.description = 'Provides a system to track method usage somewhat unobtrusively.'
15
+ spec.homepage = 'https://github.com/dhughes/is_this_used'
16
+ spec.license = 'MIT'
17
+
18
+ # Specify which files should be added to the gem when it is released.
19
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
20
+ spec.files = Dir.chdir(File.expand_path(__dir__)) 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 'activerecord', '>= 5.2'
28
+
29
+ spec.add_development_dependency 'appraisal', '~> 2.4.1'
30
+ spec.add_development_dependency 'bundler', '~> 1.17'
31
+ spec.add_development_dependency 'generator_spec', '~> 0.9.4'
32
+ spec.add_development_dependency 'mysql2', '~> 0.5.3'
33
+ spec.add_development_dependency 'pry-byebug', '~> 3.9'
34
+ spec.add_development_dependency 'rails', '>= 5.2'
35
+ spec.add_development_dependency 'rake', '~> 10.0'
36
+ spec.add_development_dependency 'rspec', '~> 3.0'
37
+ spec.add_development_dependency 'rspec-rails', '~> 5.0.2'
38
+ spec.add_development_dependency 'rubocop', '~> 1.22.2'
39
+ spec.add_development_dependency 'rubocop-rails', '~> 2.12.4'
40
+ spec.add_development_dependency 'rubocop-rake', '~> 0.6.0'
41
+ spec.add_development_dependency 'rubocop-rspec', '~> 2.5.0'
42
+ end
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rails/generators'
4
+ require 'rails/generators/active_record'
5
+
6
+ module IsThisUsed
7
+ class MigrationGenerator < Rails::Generators::Base
8
+ include Rails::Generators::Migration
9
+
10
+ source_root File.expand_path('templates', __dir__)
11
+
12
+ def create_migration_file
13
+ create_potential_crufts
14
+ create_potential_cruft_stacks
15
+ end
16
+
17
+ def self.next_migration_number(dirname)
18
+ ActiveRecord::Generators::Base.next_migration_number(dirname)
19
+ end
20
+
21
+ private
22
+
23
+ def create_potential_crufts
24
+ create_table('potential_crufts')
25
+ end
26
+
27
+ def create_potential_cruft_stacks
28
+ create_table('potential_cruft_stacks')
29
+ end
30
+
31
+ def create_table(table)
32
+ migration_template(
33
+ "create_#{table}.rb.erb",
34
+ "db/migrate/create_#{table}.rb",
35
+ { migration_version: migration_version }
36
+ )
37
+ end
38
+
39
+ def migration_version
40
+ format(
41
+ '[%d.%d]',
42
+ ActiveRecord::VERSION::MAJOR,
43
+ ActiveRecord::VERSION::MINOR
44
+ )
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,12 @@
1
+ # This migration creates the `potential_cruft_stacks` table
2
+ class CreatePotentialCruftStacks < ActiveRecord::Migration<%= migration_version %>
3
+ def change
4
+ create_table :potential_cruft_stacks do |t|
5
+ t.references :potential_cruft, null: false
6
+ t.string :stack_hash, null: false, index: true
7
+ t.json :stack, null: false
8
+ t.integer :occurrences, null: false, index: true, default: 0
9
+ t.timestamps
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,16 @@
1
+ # This migration creates the `potential_crufts` table
2
+ class CreatePotentialCrufts < ActiveRecord::Migration<%= migration_version %>
3
+ def change
4
+ create_table :potential_crufts do |t|
5
+ t.string :owner_name, null: false
6
+ t.string :method_name, null: false
7
+ t.string :method_type, null: false
8
+ t.integer :invocations, null: false, default: 0
9
+ t.timestamps
10
+
11
+ t.index :owner_name
12
+ t.index :method_name
13
+ t.index %i(owner_name method_name)
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,126 @@
1
+ # frozen_string_literal: true
2
+
3
+ module IsThisUsed
4
+ module CruftTracker
5
+ extend ActiveSupport::Concern
6
+
7
+ INSTANCE_METHOD = 'instance_method'
8
+ CLASS_METHOD = 'class_method'
9
+
10
+ class Recorder
11
+ def self.record_invocation(potential_cruft)
12
+ PotentialCruft.increment_counter(
13
+ :invocations,
14
+ potential_cruft.id,
15
+ touch: true
16
+ )
17
+ record_stack(potential_cruft)
18
+ end
19
+
20
+ def self.record_stack(potential_cruft)
21
+ stack = filtered_stack
22
+ stack_hash = Digest::MD5.hexdigest(stack.to_json)
23
+
24
+ potential_cruft_stack =
25
+ PotentialCruftStack.find_by(
26
+ potential_cruft: potential_cruft, stack_hash: stack_hash
27
+ )
28
+ potential_cruft_stack ||=
29
+ PotentialCruftStack.new(
30
+ potential_cruft: potential_cruft,
31
+ stack_hash: stack_hash,
32
+ stack: stack
33
+ )
34
+
35
+ potential_cruft_stack.occurrences += 1
36
+
37
+ potential_cruft_stack.save
38
+ end
39
+
40
+ def self.filtered_stack
41
+ caller_locations.reject do |location|
42
+ location.path.match?(%r{\/lib\/is_this_used\/cruft_tracker.rb$})
43
+ end.map do |location|
44
+ {
45
+ path: location.path,
46
+ label: location.label,
47
+ base_label: location.base_label,
48
+ lineno: location.lineno
49
+ }
50
+ end
51
+ end
52
+ end
53
+
54
+ class_methods do
55
+ def is_this_used?(method_name, method_type: nil)
56
+ method_type ||= determine_method_type(method_name)
57
+ target_method = target_method(method_name, method_type)
58
+
59
+ potential_cruft =
60
+ PotentialCruft.find_or_create_by(
61
+ owner_name: self.name,
62
+ method_name: method_name,
63
+ method_type: method_type
64
+ )
65
+
66
+ target_method.owner.define_method target_method.name do |*args|
67
+ CruftTracker::Recorder.record_invocation(potential_cruft)
68
+
69
+ if method_type == INSTANCE_METHOD
70
+ target_method.bind(self).call(*args)
71
+ else
72
+ target_method.call(*args)
73
+ end
74
+ end
75
+ end
76
+
77
+ def target_method(method_name, method_type)
78
+ case method_type
79
+ when INSTANCE_METHOD
80
+ self.instance_method(method_name)
81
+ when CLASS_METHOD
82
+ self.method(method_name)
83
+ end
84
+ end
85
+
86
+ def determine_method_type(method_name)
87
+ is_instance_method =
88
+ (self.instance_methods + self.private_instance_methods).include?(
89
+ method_name
90
+ )
91
+ is_class_method =
92
+ (self.methods + self.private_methods).include?(method_name)
93
+
94
+ if is_instance_method && is_class_method
95
+ raise AmbiguousMethodType.new(self.name, method_name)
96
+ elsif is_instance_method
97
+ INSTANCE_METHOD
98
+ elsif is_class_method
99
+ CLASS_METHOD
100
+ else
101
+ raise NoSuchMethod.new(self.name, method_name)
102
+ end
103
+ end
104
+ end
105
+ end
106
+
107
+ class AmbiguousMethodType < StandardError
108
+ def initialize(owner_name, ambiguous_method_name)
109
+ super(
110
+ "#{owner_name} has instance and class methods named '#{
111
+ ambiguous_method_name
112
+ }'. Please specify the correct type."
113
+ )
114
+ end
115
+ end
116
+
117
+ class NoSuchMethod < StandardError
118
+ def initialize(owner_name, missing_method_name)
119
+ super(
120
+ "#{owner_name} does not have an instance or class method named '#{
121
+ missing_method_name
122
+ }'."
123
+ )
124
+ end
125
+ end
126
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ module IsThisUsed
4
+ class PotentialCruft < ActiveRecord::Base
5
+ has_many :potential_cruft_stacks,
6
+ dependent: :destroy, class_name: 'IsThisUsed::PotentialCruftStack'
7
+ end
8
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module IsThisUsed
4
+ class PotentialCruftStack < ActiveRecord::Base
5
+ belongs_to :potential_cruft, class_name: 'IsThisUsed::PotentialCruft'
6
+ end
7
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module IsThisUsed
4
+ VERSION = '0.1.0'
5
+ end
@@ -0,0 +1,8 @@
1
+ require 'is_this_used/version'
2
+ require 'is_this_used/cruft_tracker'
3
+ require 'is_this_used/models/potential_cruft'
4
+ require 'is_this_used/models/potential_cruft_stack'
5
+
6
+ module IsThisUsed
7
+ class Error < StandardError; end
8
+ end
data/log/test.log ADDED
File without changes
metadata ADDED
@@ -0,0 +1,264 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: is_this_used
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Doug Hughes
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2022-01-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activerecord
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '5.2'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '5.2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: appraisal
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 2.4.1
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 2.4.1
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.17'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.17'
55
+ - !ruby/object:Gem::Dependency
56
+ name: generator_spec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.9.4
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.9.4
69
+ - !ruby/object:Gem::Dependency
70
+ name: mysql2
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 0.5.3
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 0.5.3
83
+ - !ruby/object:Gem::Dependency
84
+ name: pry-byebug
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '3.9'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '3.9'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rails
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '5.2'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '5.2'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rake
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '10.0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '10.0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: rspec
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '3.0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '3.0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: rspec-rails
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "~>"
144
+ - !ruby/object:Gem::Version
145
+ version: 5.0.2
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "~>"
151
+ - !ruby/object:Gem::Version
152
+ version: 5.0.2
153
+ - !ruby/object:Gem::Dependency
154
+ name: rubocop
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - "~>"
158
+ - !ruby/object:Gem::Version
159
+ version: 1.22.2
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - "~>"
165
+ - !ruby/object:Gem::Version
166
+ version: 1.22.2
167
+ - !ruby/object:Gem::Dependency
168
+ name: rubocop-rails
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - "~>"
172
+ - !ruby/object:Gem::Version
173
+ version: 2.12.4
174
+ type: :development
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - "~>"
179
+ - !ruby/object:Gem::Version
180
+ version: 2.12.4
181
+ - !ruby/object:Gem::Dependency
182
+ name: rubocop-rake
183
+ requirement: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - "~>"
186
+ - !ruby/object:Gem::Version
187
+ version: 0.6.0
188
+ type: :development
189
+ prerelease: false
190
+ version_requirements: !ruby/object:Gem::Requirement
191
+ requirements:
192
+ - - "~>"
193
+ - !ruby/object:Gem::Version
194
+ version: 0.6.0
195
+ - !ruby/object:Gem::Dependency
196
+ name: rubocop-rspec
197
+ requirement: !ruby/object:Gem::Requirement
198
+ requirements:
199
+ - - "~>"
200
+ - !ruby/object:Gem::Version
201
+ version: 2.5.0
202
+ type: :development
203
+ prerelease: false
204
+ version_requirements: !ruby/object:Gem::Requirement
205
+ requirements:
206
+ - - "~>"
207
+ - !ruby/object:Gem::Version
208
+ version: 2.5.0
209
+ description: Provides a system to track method usage somewhat unobtrusively.
210
+ email:
211
+ - doug@doughughes.net
212
+ executables: []
213
+ extensions: []
214
+ extra_rdoc_files: []
215
+ files:
216
+ - ".gitignore"
217
+ - ".prettierrc"
218
+ - ".rspec"
219
+ - ".travis.yml"
220
+ - Appraisals
221
+ - Gemfile
222
+ - LICENSE.txt
223
+ - README.md
224
+ - Rakefile
225
+ - bin/console
226
+ - bin/setup
227
+ - gemfiles/rails_5.2.gemfile
228
+ - gemfiles/rails_5.2.gemfile.lock
229
+ - gemfiles/rails_6.0.gemfile
230
+ - gemfiles/rails_6.0.gemfile.lock
231
+ - is_this_used.gemspec
232
+ - lib/generators/is_this_used/migration_generator.rb
233
+ - lib/generators/is_this_used/templates/create_potential_cruft_stacks.rb.erb
234
+ - lib/generators/is_this_used/templates/create_potential_crufts.rb.erb
235
+ - lib/is_this_used.rb
236
+ - lib/is_this_used/cruft_tracker.rb
237
+ - lib/is_this_used/models/potential_cruft.rb
238
+ - lib/is_this_used/models/potential_cruft_stack.rb
239
+ - lib/is_this_used/version.rb
240
+ - log/test.log
241
+ homepage: https://github.com/dhughes/is_this_used
242
+ licenses:
243
+ - MIT
244
+ metadata: {}
245
+ post_install_message:
246
+ rdoc_options: []
247
+ require_paths:
248
+ - lib
249
+ required_ruby_version: !ruby/object:Gem::Requirement
250
+ requirements:
251
+ - - ">="
252
+ - !ruby/object:Gem::Version
253
+ version: '0'
254
+ required_rubygems_version: !ruby/object:Gem::Requirement
255
+ requirements:
256
+ - - ">="
257
+ - !ruby/object:Gem::Version
258
+ version: '0'
259
+ requirements: []
260
+ rubygems_version: 3.0.3
261
+ signing_key:
262
+ specification_version: 4
263
+ summary: Provides a system to track method usage somewhat unobtrusively.
264
+ test_files: []