rails-annotate-solargraph 0.5.3 → 0.5.5
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 +4 -4
- data/.rubocop.yml +1 -1
- data/.ruby-version +1 -1
- data/.vscode/settings.json +3 -0
- data/CHANGELOG.md +7 -0
- data/Gemfile +0 -1
- data/Gemfile.lock +85 -96
- data/README.md +53 -3
- data/Rakefile +22 -4
- data/lib/generators/annotate/solargraph/install_generator.rb +4 -1
- data/lib/generators/annotate/solargraph/templates/.solargraph.yml +23 -0
- data/lib/rails/annotate/overrides.rb +14 -6
- data/lib/rails/annotate/solargraph/configuration.rb +5 -2
- data/lib/rails/annotate/solargraph/model.rb +28 -19
- data/lib/rails/annotate/solargraph/scope.rb +62 -0
- data/lib/rails/annotate/solargraph/terminal_colors.rb +1 -0
- data/lib/rails/annotate/solargraph/version.rb +1 -1
- data/lib/rails/annotate/solargraph.rb +25 -2
- data/rails-annotate-solargraph.gemspec +2 -2
- metadata +11 -9
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 58575ab157cd56c94cd086172ab769ca710e29bd15a72403a0fd0829357bab11
|
|
4
|
+
data.tar.gz: 896fdff02aa40756ecc427ef542225080581cc10f039e7a960371c22174e7891
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: d2bebaf3939fd7958b8e64fbe0cf27a397734093dda12143d5ee5fce28efc66cb199260b4e6e2f907e135f62be418df4952ec188478e1f1a6683fedcdd7527e1
|
|
7
|
+
data.tar.gz: 74a3f24690f3871be28af866deb5913e664ef71d8ae194e88d1f4883c09415dfa81430267fa8db42bd71b48709ee7229edf6315a00029d32c8bdbb4ee0f36720
|
data/.rubocop.yml
CHANGED
data/.ruby-version
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
3.0.6
|
data/.vscode/settings.json
CHANGED
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
## [Unreleased]
|
|
2
2
|
|
|
3
|
+
## [0.5.4] - 2022-08-12
|
|
4
|
+
|
|
5
|
+
- Improve scope documenting
|
|
6
|
+
- Split tests into unit tests and integration tests
|
|
7
|
+
- Remove solargraph from dependencies
|
|
8
|
+
- Improve file update messages
|
|
9
|
+
|
|
3
10
|
## [0.5.3] - 2022-04-20
|
|
4
11
|
|
|
5
12
|
- fix a minor bug which in some rails apps prevented scopes from being documented
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
|
@@ -1,75 +1,75 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
rails-annotate-solargraph (0.5.
|
|
4
|
+
rails-annotate-solargraph (0.5.5)
|
|
5
|
+
parser (~> 3)
|
|
5
6
|
rails (>= 5.0, < 8.0)
|
|
6
|
-
solargraph
|
|
7
7
|
yard
|
|
8
8
|
|
|
9
9
|
GEM
|
|
10
10
|
remote: https://rubygems.org/
|
|
11
11
|
specs:
|
|
12
|
-
actioncable (7.0.
|
|
13
|
-
actionpack (= 7.0.
|
|
14
|
-
activesupport (= 7.0.
|
|
12
|
+
actioncable (7.0.6)
|
|
13
|
+
actionpack (= 7.0.6)
|
|
14
|
+
activesupport (= 7.0.6)
|
|
15
15
|
nio4r (~> 2.0)
|
|
16
16
|
websocket-driver (>= 0.6.1)
|
|
17
|
-
actionmailbox (7.0.
|
|
18
|
-
actionpack (= 7.0.
|
|
19
|
-
activejob (= 7.0.
|
|
20
|
-
activerecord (= 7.0.
|
|
21
|
-
activestorage (= 7.0.
|
|
22
|
-
activesupport (= 7.0.
|
|
17
|
+
actionmailbox (7.0.6)
|
|
18
|
+
actionpack (= 7.0.6)
|
|
19
|
+
activejob (= 7.0.6)
|
|
20
|
+
activerecord (= 7.0.6)
|
|
21
|
+
activestorage (= 7.0.6)
|
|
22
|
+
activesupport (= 7.0.6)
|
|
23
23
|
mail (>= 2.7.1)
|
|
24
24
|
net-imap
|
|
25
25
|
net-pop
|
|
26
26
|
net-smtp
|
|
27
|
-
actionmailer (7.0.
|
|
28
|
-
actionpack (= 7.0.
|
|
29
|
-
actionview (= 7.0.
|
|
30
|
-
activejob (= 7.0.
|
|
31
|
-
activesupport (= 7.0.
|
|
27
|
+
actionmailer (7.0.6)
|
|
28
|
+
actionpack (= 7.0.6)
|
|
29
|
+
actionview (= 7.0.6)
|
|
30
|
+
activejob (= 7.0.6)
|
|
31
|
+
activesupport (= 7.0.6)
|
|
32
32
|
mail (~> 2.5, >= 2.5.4)
|
|
33
33
|
net-imap
|
|
34
34
|
net-pop
|
|
35
35
|
net-smtp
|
|
36
36
|
rails-dom-testing (~> 2.0)
|
|
37
|
-
actionpack (7.0.
|
|
38
|
-
actionview (= 7.0.
|
|
39
|
-
activesupport (= 7.0.
|
|
40
|
-
rack (~> 2.0, >= 2.2.
|
|
37
|
+
actionpack (7.0.6)
|
|
38
|
+
actionview (= 7.0.6)
|
|
39
|
+
activesupport (= 7.0.6)
|
|
40
|
+
rack (~> 2.0, >= 2.2.4)
|
|
41
41
|
rack-test (>= 0.6.3)
|
|
42
42
|
rails-dom-testing (~> 2.0)
|
|
43
43
|
rails-html-sanitizer (~> 1.0, >= 1.2.0)
|
|
44
|
-
actiontext (7.0.
|
|
45
|
-
actionpack (= 7.0.
|
|
46
|
-
activerecord (= 7.0.
|
|
47
|
-
activestorage (= 7.0.
|
|
48
|
-
activesupport (= 7.0.
|
|
44
|
+
actiontext (7.0.6)
|
|
45
|
+
actionpack (= 7.0.6)
|
|
46
|
+
activerecord (= 7.0.6)
|
|
47
|
+
activestorage (= 7.0.6)
|
|
48
|
+
activesupport (= 7.0.6)
|
|
49
49
|
globalid (>= 0.6.0)
|
|
50
50
|
nokogiri (>= 1.8.5)
|
|
51
|
-
actionview (7.0.
|
|
52
|
-
activesupport (= 7.0.
|
|
51
|
+
actionview (7.0.6)
|
|
52
|
+
activesupport (= 7.0.6)
|
|
53
53
|
builder (~> 3.1)
|
|
54
54
|
erubi (~> 1.4)
|
|
55
55
|
rails-dom-testing (~> 2.0)
|
|
56
56
|
rails-html-sanitizer (~> 1.1, >= 1.2.0)
|
|
57
|
-
activejob (7.0.
|
|
58
|
-
activesupport (= 7.0.
|
|
57
|
+
activejob (7.0.6)
|
|
58
|
+
activesupport (= 7.0.6)
|
|
59
59
|
globalid (>= 0.3.6)
|
|
60
|
-
activemodel (7.0.
|
|
61
|
-
activesupport (= 7.0.
|
|
62
|
-
activerecord (7.0.
|
|
63
|
-
activemodel (= 7.0.
|
|
64
|
-
activesupport (= 7.0.
|
|
65
|
-
activestorage (7.0.
|
|
66
|
-
actionpack (= 7.0.
|
|
67
|
-
activejob (= 7.0.
|
|
68
|
-
activerecord (= 7.0.
|
|
69
|
-
activesupport (= 7.0.
|
|
60
|
+
activemodel (7.0.6)
|
|
61
|
+
activesupport (= 7.0.6)
|
|
62
|
+
activerecord (7.0.6)
|
|
63
|
+
activemodel (= 7.0.6)
|
|
64
|
+
activesupport (= 7.0.6)
|
|
65
|
+
activestorage (7.0.6)
|
|
66
|
+
actionpack (= 7.0.6)
|
|
67
|
+
activejob (= 7.0.6)
|
|
68
|
+
activerecord (= 7.0.6)
|
|
69
|
+
activesupport (= 7.0.6)
|
|
70
70
|
marcel (~> 1.0)
|
|
71
71
|
mini_mime (>= 1.1.0)
|
|
72
|
-
activesupport (7.0.
|
|
72
|
+
activesupport (7.0.6)
|
|
73
73
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
|
74
74
|
i18n (>= 1.6, < 2)
|
|
75
75
|
minitest (>= 5.1)
|
|
@@ -79,54 +79,46 @@ GEM
|
|
|
79
79
|
benchmark (0.2.0)
|
|
80
80
|
builder (3.2.4)
|
|
81
81
|
byebug (11.1.3)
|
|
82
|
-
concurrent-ruby (1.
|
|
82
|
+
concurrent-ruby (1.2.2)
|
|
83
83
|
crass (1.0.6)
|
|
84
|
-
|
|
85
|
-
irb (>= 1.3.6)
|
|
86
|
-
reline (>= 0.2.7)
|
|
84
|
+
date (3.3.3)
|
|
87
85
|
diff-lcs (1.5.0)
|
|
88
|
-
digest (3.1.0)
|
|
89
86
|
e2mmap (0.1.0)
|
|
90
|
-
erubi (1.
|
|
87
|
+
erubi (1.12.0)
|
|
91
88
|
git (1.10.2)
|
|
92
89
|
rchardet (~> 1.8)
|
|
93
|
-
globalid (1.
|
|
90
|
+
globalid (1.1.0)
|
|
94
91
|
activesupport (>= 5.0)
|
|
95
|
-
i18n (1.
|
|
92
|
+
i18n (1.14.1)
|
|
96
93
|
concurrent-ruby (~> 1.0)
|
|
97
|
-
io-console (0.5.11)
|
|
98
|
-
irb (1.4.1)
|
|
99
|
-
reline (>= 0.3.0)
|
|
100
94
|
jaro_winkler (1.5.4)
|
|
101
95
|
kramdown (2.3.2)
|
|
102
96
|
rexml
|
|
103
97
|
kramdown-parser-gfm (1.1.0)
|
|
104
98
|
kramdown (~> 2.0)
|
|
105
|
-
loofah (2.
|
|
99
|
+
loofah (2.21.3)
|
|
106
100
|
crass (~> 1.0.2)
|
|
107
|
-
nokogiri (>= 1.
|
|
108
|
-
mail (2.
|
|
101
|
+
nokogiri (>= 1.12.0)
|
|
102
|
+
mail (2.8.1)
|
|
109
103
|
mini_mime (>= 0.1.1)
|
|
104
|
+
net-imap
|
|
105
|
+
net-pop
|
|
106
|
+
net-smtp
|
|
110
107
|
marcel (1.0.2)
|
|
111
108
|
method_source (1.0.0)
|
|
112
109
|
mini_mime (1.1.2)
|
|
113
110
|
mini_portile2 (2.8.0)
|
|
114
111
|
minitest (5.15.0)
|
|
115
|
-
net-imap (0.
|
|
116
|
-
|
|
112
|
+
net-imap (0.3.6)
|
|
113
|
+
date
|
|
117
114
|
net-protocol
|
|
118
|
-
|
|
119
|
-
net-pop (0.1.1)
|
|
120
|
-
digest
|
|
115
|
+
net-pop (0.1.2)
|
|
121
116
|
net-protocol
|
|
117
|
+
net-protocol (0.2.1)
|
|
122
118
|
timeout
|
|
123
|
-
net-
|
|
124
|
-
timeout
|
|
125
|
-
net-smtp (0.3.1)
|
|
126
|
-
digest
|
|
119
|
+
net-smtp (0.3.3)
|
|
127
120
|
net-protocol
|
|
128
|
-
|
|
129
|
-
nio4r (2.5.8)
|
|
121
|
+
nio4r (2.5.9)
|
|
130
122
|
nokogiri (1.13.4)
|
|
131
123
|
mini_portile2 (~> 2.8.0)
|
|
132
124
|
racc (~> 1.4)
|
|
@@ -136,31 +128,32 @@ GEM
|
|
|
136
128
|
parser (3.1.1.0)
|
|
137
129
|
ast (~> 2.4.1)
|
|
138
130
|
racc (1.6.0)
|
|
139
|
-
rack (2.2.
|
|
140
|
-
rack-test (
|
|
141
|
-
rack (>= 1.
|
|
142
|
-
rails (7.0.
|
|
143
|
-
actioncable (= 7.0.
|
|
144
|
-
actionmailbox (= 7.0.
|
|
145
|
-
actionmailer (= 7.0.
|
|
146
|
-
actionpack (= 7.0.
|
|
147
|
-
actiontext (= 7.0.
|
|
148
|
-
actionview (= 7.0.
|
|
149
|
-
activejob (= 7.0.
|
|
150
|
-
activemodel (= 7.0.
|
|
151
|
-
activerecord (= 7.0.
|
|
152
|
-
activestorage (= 7.0.
|
|
153
|
-
activesupport (= 7.0.
|
|
131
|
+
rack (2.2.7)
|
|
132
|
+
rack-test (2.1.0)
|
|
133
|
+
rack (>= 1.3)
|
|
134
|
+
rails (7.0.6)
|
|
135
|
+
actioncable (= 7.0.6)
|
|
136
|
+
actionmailbox (= 7.0.6)
|
|
137
|
+
actionmailer (= 7.0.6)
|
|
138
|
+
actionpack (= 7.0.6)
|
|
139
|
+
actiontext (= 7.0.6)
|
|
140
|
+
actionview (= 7.0.6)
|
|
141
|
+
activejob (= 7.0.6)
|
|
142
|
+
activemodel (= 7.0.6)
|
|
143
|
+
activerecord (= 7.0.6)
|
|
144
|
+
activestorage (= 7.0.6)
|
|
145
|
+
activesupport (= 7.0.6)
|
|
154
146
|
bundler (>= 1.15.0)
|
|
155
|
-
railties (= 7.0.
|
|
156
|
-
rails-dom-testing (2.
|
|
157
|
-
activesupport (>=
|
|
147
|
+
railties (= 7.0.6)
|
|
148
|
+
rails-dom-testing (2.1.1)
|
|
149
|
+
activesupport (>= 5.0.0)
|
|
150
|
+
minitest
|
|
158
151
|
nokogiri (>= 1.6)
|
|
159
|
-
rails-html-sanitizer (1.
|
|
160
|
-
loofah (~> 2.
|
|
161
|
-
railties (7.0.
|
|
162
|
-
actionpack (= 7.0.
|
|
163
|
-
activesupport (= 7.0.
|
|
152
|
+
rails-html-sanitizer (1.5.0)
|
|
153
|
+
loofah (~> 2.19, >= 2.19.1)
|
|
154
|
+
railties (7.0.6)
|
|
155
|
+
actionpack (= 7.0.6)
|
|
156
|
+
activesupport (= 7.0.6)
|
|
164
157
|
method_source
|
|
165
158
|
rake (>= 12.2)
|
|
166
159
|
thor (~> 1.0)
|
|
@@ -169,8 +162,6 @@ GEM
|
|
|
169
162
|
rake (13.0.6)
|
|
170
163
|
rchardet (1.8.0)
|
|
171
164
|
regexp_parser (2.2.1)
|
|
172
|
-
reline (0.3.1)
|
|
173
|
-
io-console (~> 0.5)
|
|
174
165
|
reverse_markdown (2.1.1)
|
|
175
166
|
nokogiri
|
|
176
167
|
rexml (3.2.5)
|
|
@@ -202,20 +193,19 @@ GEM
|
|
|
202
193
|
tilt (~> 2.0)
|
|
203
194
|
yard (~> 0.9, >= 0.9.24)
|
|
204
195
|
sqlite3 (1.4.2)
|
|
205
|
-
strscan (3.0.1)
|
|
206
196
|
thor (1.2.1)
|
|
207
197
|
tilt (2.0.10)
|
|
208
|
-
timeout (0.
|
|
209
|
-
tzinfo (2.0.
|
|
198
|
+
timeout (0.4.0)
|
|
199
|
+
tzinfo (2.0.6)
|
|
210
200
|
concurrent-ruby (~> 1.0)
|
|
211
201
|
unicode-display_width (2.1.0)
|
|
212
202
|
webrick (1.7.0)
|
|
213
|
-
websocket-driver (0.7.
|
|
203
|
+
websocket-driver (0.7.6)
|
|
214
204
|
websocket-extensions (>= 0.1.0)
|
|
215
205
|
websocket-extensions (0.1.5)
|
|
216
206
|
yard (0.9.27)
|
|
217
207
|
webrick (~> 1.7.0)
|
|
218
|
-
zeitwerk (2.
|
|
208
|
+
zeitwerk (2.6.9)
|
|
219
209
|
|
|
220
210
|
PLATFORMS
|
|
221
211
|
arm64-darwin-20
|
|
@@ -223,7 +213,6 @@ PLATFORMS
|
|
|
223
213
|
|
|
224
214
|
DEPENDENCIES
|
|
225
215
|
byebug
|
|
226
|
-
debug
|
|
227
216
|
git
|
|
228
217
|
minitest (~> 5.0)
|
|
229
218
|
rails-annotate-solargraph!
|
data/README.md
CHANGED
|
@@ -74,7 +74,7 @@ end
|
|
|
74
74
|
|
|
75
75
|
There are a few values for this option:
|
|
76
76
|
|
|
77
|
-
- `:schema_file` -- default value, annotations get saved to a special file
|
|
77
|
+
- `:schema_file` -- default value, annotations get saved to a special file `.annotate_solargraph_schema`
|
|
78
78
|
- `:bottom` -- annotations are appended to the model files
|
|
79
79
|
- `:top` -- annotations are prepended to the model files
|
|
80
80
|
|
|
@@ -90,9 +90,59 @@ $ rake annotate:solargraph:generate
|
|
|
90
90
|
|
|
91
91
|
## Development
|
|
92
92
|
|
|
93
|
-
|
|
93
|
+
### Setup
|
|
94
94
|
|
|
95
|
-
To
|
|
95
|
+
To setup this gem for development you should use the setup script.
|
|
96
|
+
|
|
97
|
+
```sh
|
|
98
|
+
$ bin/setup
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
### Console
|
|
102
|
+
|
|
103
|
+
You can access an IRB with this entire gem preloaded like this
|
|
104
|
+
|
|
105
|
+
```sh
|
|
106
|
+
$ bin/console
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
### Tests
|
|
110
|
+
|
|
111
|
+
You can run all tests with:
|
|
112
|
+
|
|
113
|
+
```sh
|
|
114
|
+
$ rake test
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
All unit tests:
|
|
118
|
+
|
|
119
|
+
```sh
|
|
120
|
+
$ rake test:unit
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
All integration tests:
|
|
124
|
+
|
|
125
|
+
```sh
|
|
126
|
+
$ rake test:integration
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
### Release
|
|
130
|
+
|
|
131
|
+
To release a new version, update the version number in `version.rb`, and then run
|
|
132
|
+
|
|
133
|
+
```sh
|
|
134
|
+
$ bundle exec rake release
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
This will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
|
138
|
+
|
|
139
|
+
### Local installation
|
|
140
|
+
|
|
141
|
+
To install this gem onto your local machine, run
|
|
142
|
+
|
|
143
|
+
```sh
|
|
144
|
+
$ bundle exec rake install
|
|
145
|
+
```
|
|
96
146
|
|
|
97
147
|
## Contributing
|
|
98
148
|
|
data/Rakefile
CHANGED
|
@@ -3,10 +3,28 @@
|
|
|
3
3
|
require "bundler/gem_tasks"
|
|
4
4
|
require "rake/testtask"
|
|
5
5
|
|
|
6
|
-
Rake::TestTask.new(:test) do |t|
|
|
7
|
-
t.libs <<
|
|
8
|
-
t.libs <<
|
|
9
|
-
t.
|
|
6
|
+
::Rake::TestTask.new(:test) do |t|
|
|
7
|
+
t.libs << 'lib'
|
|
8
|
+
t.libs << 'test'
|
|
9
|
+
t.libs << 'test/fixtures'
|
|
10
|
+
# ignore tests of rails apps
|
|
11
|
+
t.test_files = ::FileList['test/**/*_test.rb'] - ::FileList['test/dummy/**/*_test.rb']
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
::Rake::TestTask.new('test:unit') do |t|
|
|
15
|
+
t.libs << 'lib'
|
|
16
|
+
t.libs << 'test'
|
|
17
|
+
t.libs << 'test/fixtures'
|
|
18
|
+
# ignore tests of rails apps
|
|
19
|
+
t.test_files = ::FileList['test/unit/**/*_test.rb']
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
::Rake::TestTask.new('test:integration') do |t|
|
|
23
|
+
t.libs << 'lib'
|
|
24
|
+
t.libs << 'test'
|
|
25
|
+
t.libs << 'test/fixtures'
|
|
26
|
+
# ignore tests of rails apps
|
|
27
|
+
t.test_files = ::FileList['test/integration/**/*_test.rb']
|
|
10
28
|
end
|
|
11
29
|
|
|
12
30
|
require "rubocop/rake_task"
|
|
@@ -16,7 +16,10 @@ module Annotate
|
|
|
16
16
|
template ::Rails::Annotate::Solargraph::SCHEMA_FILE_NAME, ::Rails::Annotate::Solargraph::SCHEMA_RAILS_PATH
|
|
17
17
|
|
|
18
18
|
solargraph_config_file = ::File.join(::Rails.root, ::Rails::Annotate::Solargraph::SOLARGRAPH_FILE_NAME)
|
|
19
|
-
|
|
19
|
+
unless ::File.exist? solargraph_config_file
|
|
20
|
+
template(::Rails::Annotate::Solargraph::SOLARGRAPH_FILE_NAME, ::Rails::Annotate::Solargraph::SOLARGRAPH_FILE_PATH)
|
|
21
|
+
end
|
|
22
|
+
|
|
20
23
|
solargraph_config = ::YAML.load_file solargraph_config_file
|
|
21
24
|
solargraph_config['include'] = solargraph_config['include'] || []
|
|
22
25
|
solargraph_config['include'].unshift ::Rails::Annotate::Solargraph::SCHEMA_RAILS_PATH
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
---
|
|
2
|
+
include:
|
|
3
|
+
- ".annotate_solargraph_schema"
|
|
4
|
+
- "**/*.rb"
|
|
5
|
+
exclude:
|
|
6
|
+
- spec/**/*
|
|
7
|
+
- test/**/*
|
|
8
|
+
- vendor/**/*
|
|
9
|
+
- ".bundle/**/*"
|
|
10
|
+
require: []
|
|
11
|
+
domains: []
|
|
12
|
+
reporters:
|
|
13
|
+
- rubocop
|
|
14
|
+
- require_not_found
|
|
15
|
+
formatter:
|
|
16
|
+
rubocop:
|
|
17
|
+
cops: safe
|
|
18
|
+
except: []
|
|
19
|
+
only: []
|
|
20
|
+
extra_args: []
|
|
21
|
+
require_paths: []
|
|
22
|
+
plugins: []
|
|
23
|
+
max_files: 5000
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require 'parser/current'
|
|
4
|
+
|
|
3
5
|
class ActiveRecord::Base
|
|
4
6
|
class << self
|
|
5
7
|
alias orig_scope scope
|
|
@@ -10,22 +12,28 @@ class ActiveRecord::Base
|
|
|
10
12
|
scope_name = args.first
|
|
11
13
|
scope_proc = args[1]
|
|
12
14
|
proc_parameters = scope_proc.respond_to?(:parameters) ? scope_proc.parameters.map(&:last) : []
|
|
13
|
-
|
|
15
|
+
scope_definition = ::String.new
|
|
14
16
|
scope_model_class = self
|
|
17
|
+
scope_lines = 0
|
|
18
|
+
scope_indentation = nil
|
|
15
19
|
|
|
16
20
|
::File.open(file_path) do |file|
|
|
17
21
|
file.each_line.with_index(1) do |line, current_line_number|
|
|
18
|
-
next
|
|
22
|
+
next if current_line_number < scope_line_number
|
|
23
|
+
break if scope_lines > 50
|
|
24
|
+
|
|
25
|
+
scope_indentation ||= line.length - line.lstrip.length
|
|
26
|
+
scope_definition << "#{line.rstrip[scope_indentation..]}\n"
|
|
27
|
+
scope_lines += 1
|
|
19
28
|
|
|
20
|
-
|
|
21
|
-
break
|
|
29
|
+
break if ::Parser::CurrentRuby.new.parse ::Parser::Source::Buffer.new('(string)', source: scope_definition)
|
|
22
30
|
end
|
|
23
31
|
end
|
|
24
32
|
|
|
25
|
-
::Rails::Annotate::Solargraph::Model.add_scope(scope_name.to_sym, scope_model_class, proc_parameters,
|
|
33
|
+
::Rails::Annotate::Solargraph::Model.add_scope(scope_name.to_sym, scope_model_class, proc_parameters, scope_definition)
|
|
26
34
|
|
|
27
35
|
orig_scope(*args, **kwargs, &block)
|
|
28
|
-
rescue
|
|
36
|
+
rescue ::StandardError
|
|
29
37
|
orig_scope(*args, **kwargs, &block)
|
|
30
38
|
end
|
|
31
39
|
end
|
|
@@ -17,8 +17,11 @@ module Rails
|
|
|
17
17
|
|
|
18
18
|
# @param val [Symbol]
|
|
19
19
|
def annotation_position=(val)
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
unless ANNOTATION_POSITIONS.include?(val)
|
|
21
|
+
raise Error,
|
|
22
|
+
"`annotation_position` is incorrect! Got `#{val.inspect}`, " \
|
|
23
|
+
"expected a member of `#{ANNOTATION_POSITIONS.inspect}`"
|
|
24
|
+
end
|
|
22
25
|
|
|
23
26
|
@annotation_position = val
|
|
24
27
|
end
|
|
@@ -8,10 +8,9 @@ module Rails
|
|
|
8
8
|
class Model
|
|
9
9
|
using TerminalColors::Refinement
|
|
10
10
|
|
|
11
|
-
Scope = ::Struct.new(:name, :model_class, :proc_parameters, :definition, keyword_init: true)
|
|
12
|
-
|
|
13
11
|
# @return [Regexp]
|
|
14
|
-
MAGIC_COMMENT_REGEXP =
|
|
12
|
+
MAGIC_COMMENT_REGEXP =
|
|
13
|
+
/(^#\s*encoding:.*(?:\n|r\n))|(^# coding:.*(?:\n|\r\n))|(^# -\*- coding:.*(?:\n|\r\n))|(^# -\*- encoding\s?:.*(?:\n|\r\n))|(^#\s*frozen_string_literal:.+(?:\n|\r\n))|(^# -\*- frozen_string_literal\s*:.+-\*-(?:\n|\r\n))/
|
|
15
14
|
|
|
16
15
|
# @return [Hash{Symbol => String}]
|
|
17
16
|
TYPE_MAP = {
|
|
@@ -45,11 +44,17 @@ module Rails
|
|
|
45
44
|
# @param proc_parameters [Array<Symbol>]
|
|
46
45
|
# @param definition [String]
|
|
47
46
|
def add_scope(name, model_class, proc_parameters, definition)
|
|
48
|
-
scope = Scope.new(
|
|
47
|
+
scope = Scope.new(
|
|
48
|
+
name: name,
|
|
49
|
+
model_class: model_class,
|
|
50
|
+
proc_parameters: proc_parameters,
|
|
51
|
+
definition: definition
|
|
52
|
+
)
|
|
53
|
+
|
|
49
54
|
@scopes ||= {}
|
|
50
55
|
@scopes[model_class] ||= []
|
|
51
56
|
@scopes[model_class] << scope
|
|
52
|
-
@scopes[model_class].sort_by!
|
|
57
|
+
@scopes[model_class].sort_by!(&:name)
|
|
53
58
|
end
|
|
54
59
|
|
|
55
60
|
# @param klass [Class]
|
|
@@ -82,7 +87,12 @@ module Rails
|
|
|
82
87
|
# @param klass [Class]
|
|
83
88
|
def initialize(klass)
|
|
84
89
|
@klass = klass
|
|
85
|
-
@file_name =
|
|
90
|
+
@file_name =
|
|
91
|
+
if CONFIG.schema_file?
|
|
92
|
+
SCHEMA_RAILS_PATH
|
|
93
|
+
else
|
|
94
|
+
::File.join(::Rails.root, MODEL_DIR, "#{klass.to_s.underscore}.rb")
|
|
95
|
+
end
|
|
86
96
|
end
|
|
87
97
|
|
|
88
98
|
# @return [String]
|
|
@@ -100,10 +110,11 @@ module Rails
|
|
|
100
110
|
self.class.annotation_regexp(@klass)
|
|
101
111
|
end
|
|
102
112
|
|
|
103
|
-
# @param
|
|
113
|
+
# @param write [Boolean]
|
|
104
114
|
# @return [String] New file content.
|
|
105
115
|
def annotate(write: true)
|
|
106
116
|
old_content, file_content = remove_annotation write: false
|
|
117
|
+
return old_content if @klass.abstract_class
|
|
107
118
|
|
|
108
119
|
if CONFIG.annotation_position == :top
|
|
109
120
|
magic_comments = file_content.scan(MAGIC_COMMENT_REGEXP).flatten.compact.join
|
|
@@ -121,7 +132,7 @@ module Rails
|
|
|
121
132
|
new_file_content
|
|
122
133
|
end
|
|
123
134
|
|
|
124
|
-
# @param
|
|
135
|
+
# @param write [Boolean]
|
|
125
136
|
# @return [Array<String>] Old file content followed by new content.
|
|
126
137
|
def remove_annotation(write: true)
|
|
127
138
|
return ['', ''] unless ::File.exist?(@file_name)
|
|
@@ -162,18 +173,16 @@ module Rails
|
|
|
162
173
|
|
|
163
174
|
private
|
|
164
175
|
|
|
176
|
+
# @return [Array<Scope>]
|
|
177
|
+
def scopes
|
|
178
|
+
self.class.scopes[@klass]
|
|
179
|
+
end
|
|
180
|
+
|
|
165
181
|
# @param doc_string [String]
|
|
166
182
|
# @return [void]
|
|
167
183
|
def document_scopes(doc_string)
|
|
168
|
-
|
|
169
|
-
doc_string <<
|
|
170
|
-
# # Scope `#{scope.name.inspect}`.
|
|
171
|
-
# #
|
|
172
|
-
# # #{scope.definition}
|
|
173
|
-
# #
|
|
174
|
-
# # @return [Array<#{@klass}>, nil]
|
|
175
|
-
# def self.#{scope.name}(#{scope.proc_parameters.join(', ')}); end
|
|
176
|
-
DOC
|
|
184
|
+
scopes&.each do |scope|
|
|
185
|
+
doc_string << scope.documentation
|
|
177
186
|
end
|
|
178
187
|
end
|
|
179
188
|
|
|
@@ -219,9 +228,9 @@ module Rails
|
|
|
219
228
|
# @param content [String]
|
|
220
229
|
# @return [void]
|
|
221
230
|
def write_file(file_name, content)
|
|
222
|
-
::FileUtils.touch(file_name) unless ::File.
|
|
231
|
+
::FileUtils.touch(file_name) unless ::File.exist?(file_name)
|
|
223
232
|
::File.write(file_name, content)
|
|
224
|
-
puts "modify".rjust(12).with_styles(:bold, :green) + " #{relative_file_name(file_name)}"
|
|
233
|
+
puts "modify".rjust(12).with_styles(:bold, :green) + " #{relative_file_name(file_name)} (#{@klass})"
|
|
225
234
|
end
|
|
226
235
|
|
|
227
236
|
# @return [String]
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Rails
|
|
4
|
+
module Annotate
|
|
5
|
+
module Solargraph
|
|
6
|
+
# Represents a scope on an ActiveRecord Model.
|
|
7
|
+
class Scope
|
|
8
|
+
# @param name [Symbol]
|
|
9
|
+
attr_reader :name
|
|
10
|
+
# @param model_class [Class]
|
|
11
|
+
attr_reader :model_class
|
|
12
|
+
# @param proc_parameters [Array<Symbol>]
|
|
13
|
+
attr_reader :proc_parameters
|
|
14
|
+
# @param definition [String]
|
|
15
|
+
attr_reader :definition
|
|
16
|
+
|
|
17
|
+
# @param name [Symbol]
|
|
18
|
+
# @param model_class [Class]
|
|
19
|
+
# @param proc_parameters [Array<Symbol>]
|
|
20
|
+
# @param definition [String]
|
|
21
|
+
def initialize(name:, model_class:, proc_parameters:, definition:)
|
|
22
|
+
@name = name
|
|
23
|
+
@model_class = model_class
|
|
24
|
+
@proc_parameters = proc_parameters
|
|
25
|
+
@definition = definition
|
|
26
|
+
freeze
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
# @return [String]
|
|
30
|
+
def documentation
|
|
31
|
+
<<~DOC
|
|
32
|
+
# # Scope `#{@name.inspect}`.
|
|
33
|
+
# #
|
|
34
|
+
#{documented_definition}
|
|
35
|
+
# #
|
|
36
|
+
# # @return [Array<#{@model_class}>, nil]
|
|
37
|
+
# #{signature}
|
|
38
|
+
DOC
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
private
|
|
42
|
+
|
|
43
|
+
# @return [String]
|
|
44
|
+
def signature
|
|
45
|
+
args = @proc_parameters.join(', ')
|
|
46
|
+
|
|
47
|
+
"def self.#{@name}(#{args}); end"
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
# @return [String]
|
|
51
|
+
def documented_definition
|
|
52
|
+
result = ::String.new
|
|
53
|
+
@definition.each_line do |line|
|
|
54
|
+
result << "# # #{line}"
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
result.chomp
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
end
|
|
@@ -6,11 +6,12 @@ require 'fileutils'
|
|
|
6
6
|
require_relative "solargraph/version"
|
|
7
7
|
require_relative "solargraph/configuration"
|
|
8
8
|
require_relative "solargraph/terminal_colors"
|
|
9
|
+
require_relative "solargraph/scope"
|
|
9
10
|
require_relative "solargraph/model"
|
|
10
11
|
|
|
11
12
|
begin
|
|
12
13
|
require_relative "overrides"
|
|
13
|
-
rescue
|
|
14
|
+
rescue ::StandardError
|
|
14
15
|
nil
|
|
15
16
|
end
|
|
16
17
|
|
|
@@ -31,6 +32,8 @@ module Rails
|
|
|
31
32
|
# @return [String]
|
|
32
33
|
SOLARGRAPH_FILE_NAME = '.solargraph.yml'
|
|
33
34
|
# @return [String]
|
|
35
|
+
SOLARGRAPH_FILE_PATH = SOLARGRAPH_FILE_NAME
|
|
36
|
+
# @return [String]
|
|
34
37
|
SCHEMA_FILE_NAME = '.annotate_solargraph_schema'
|
|
35
38
|
# @return [String]
|
|
36
39
|
SCHEMA_RAILS_PATH = SCHEMA_FILE_NAME
|
|
@@ -58,11 +61,31 @@ module Rails
|
|
|
58
61
|
|
|
59
62
|
# @return [Array<ActiveRecord::Base>]
|
|
60
63
|
def model_classes
|
|
61
|
-
@model_classes ||=
|
|
64
|
+
@model_classes ||= begin
|
|
65
|
+
base_abstract_class = begin
|
|
66
|
+
::ApplicationRecord
|
|
67
|
+
rescue
|
|
68
|
+
::ActiveRecord::Base
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
extract_subclasses(base_abstract_class).sort_by(&:name)
|
|
72
|
+
end
|
|
62
73
|
end
|
|
63
74
|
|
|
64
75
|
private
|
|
65
76
|
|
|
77
|
+
# @param klass [Class]
|
|
78
|
+
# @return [Array<Class>]
|
|
79
|
+
def extract_subclasses(klass)
|
|
80
|
+
result = []
|
|
81
|
+
klass.subclasses.each do |k|
|
|
82
|
+
result << k
|
|
83
|
+
result.concat(extract_subclasses(k))
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
result
|
|
87
|
+
end
|
|
88
|
+
|
|
66
89
|
include TerminalColors
|
|
67
90
|
|
|
68
91
|
def create_schema_file
|
|
@@ -12,7 +12,7 @@ Gem::Specification.new do |spec|
|
|
|
12
12
|
spec.description = "Annotate ActiveRecord models with schema comments formatted in YARD that are compatible with Solargraph."
|
|
13
13
|
spec.homepage = "https://gitlab.com/mateuszdrewniak/rails-annotate-solargraph"
|
|
14
14
|
spec.license = "MIT"
|
|
15
|
-
spec.required_ruby_version = ">=
|
|
15
|
+
spec.required_ruby_version = ">= 3.0.0"
|
|
16
16
|
|
|
17
17
|
spec.metadata["homepage_uri"] = spec.homepage
|
|
18
18
|
spec.metadata["source_code_uri"] = "https://gitlab.com/mateuszdrewniak/rails-annotate-solargraph"
|
|
@@ -31,7 +31,7 @@ Gem::Specification.new do |spec|
|
|
|
31
31
|
|
|
32
32
|
# Uncomment to register a new dependency of your gem
|
|
33
33
|
spec.add_dependency 'rails', ">= 5.0", '< 8.0'
|
|
34
|
-
spec.add_dependency '
|
|
34
|
+
spec.add_dependency 'parser', '~> 3'
|
|
35
35
|
spec.add_dependency 'yard'
|
|
36
36
|
|
|
37
37
|
# For more information and examples about making a new gem, check out our
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: rails-annotate-solargraph
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.5.
|
|
4
|
+
version: 0.5.5
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Mateusz Drewniak
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2023-07-26 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rails
|
|
@@ -31,19 +31,19 @@ dependencies:
|
|
|
31
31
|
- !ruby/object:Gem::Version
|
|
32
32
|
version: '8.0'
|
|
33
33
|
- !ruby/object:Gem::Dependency
|
|
34
|
-
name:
|
|
34
|
+
name: parser
|
|
35
35
|
requirement: !ruby/object:Gem::Requirement
|
|
36
36
|
requirements:
|
|
37
|
-
- - "
|
|
37
|
+
- - "~>"
|
|
38
38
|
- !ruby/object:Gem::Version
|
|
39
|
-
version: '
|
|
39
|
+
version: '3'
|
|
40
40
|
type: :runtime
|
|
41
41
|
prerelease: false
|
|
42
42
|
version_requirements: !ruby/object:Gem::Requirement
|
|
43
43
|
requirements:
|
|
44
|
-
- - "
|
|
44
|
+
- - "~>"
|
|
45
45
|
- !ruby/object:Gem::Version
|
|
46
|
-
version: '
|
|
46
|
+
version: '3'
|
|
47
47
|
- !ruby/object:Gem::Dependency
|
|
48
48
|
name: yard
|
|
49
49
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -82,11 +82,13 @@ files:
|
|
|
82
82
|
- bin/setup
|
|
83
83
|
- lib/generators/annotate/solargraph/install_generator.rb
|
|
84
84
|
- lib/generators/annotate/solargraph/templates/.annotate_solargraph_schema
|
|
85
|
+
- lib/generators/annotate/solargraph/templates/.solargraph.yml
|
|
85
86
|
- lib/generators/annotate/solargraph/templates/rails_annotate_solargraph.rake
|
|
86
87
|
- lib/rails/annotate/overrides.rb
|
|
87
88
|
- lib/rails/annotate/solargraph.rb
|
|
88
89
|
- lib/rails/annotate/solargraph/configuration.rb
|
|
89
90
|
- lib/rails/annotate/solargraph/model.rb
|
|
91
|
+
- lib/rails/annotate/solargraph/scope.rb
|
|
90
92
|
- lib/rails/annotate/solargraph/terminal_colors.rb
|
|
91
93
|
- lib/rails/annotate/solargraph/version.rb
|
|
92
94
|
- rails-annotate-solargraph.gemspec
|
|
@@ -106,14 +108,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
106
108
|
requirements:
|
|
107
109
|
- - ">="
|
|
108
110
|
- !ruby/object:Gem::Version
|
|
109
|
-
version:
|
|
111
|
+
version: 3.0.0
|
|
110
112
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
111
113
|
requirements:
|
|
112
114
|
- - ">="
|
|
113
115
|
- !ruby/object:Gem::Version
|
|
114
116
|
version: '0'
|
|
115
117
|
requirements: []
|
|
116
|
-
rubygems_version: 3.
|
|
118
|
+
rubygems_version: 3.2.33
|
|
117
119
|
signing_key:
|
|
118
120
|
specification_version: 4
|
|
119
121
|
summary: Annotate ActiveRecord models with schema comments formatted in YARD that
|