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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f47a9a65cb37174ca12847169325afbecef1182e7d34bf555accf5551fbb7f1c
4
- data.tar.gz: 97d1aae264b49adc45222847f6d2f25278abacec90134226cc7c023e205df6d5
3
+ metadata.gz: 58575ab157cd56c94cd086172ab769ca710e29bd15a72403a0fd0829357bab11
4
+ data.tar.gz: 896fdff02aa40756ecc427ef542225080581cc10f039e7a960371c22174e7891
5
5
  SHA512:
6
- metadata.gz: fa14e6c6068da07e1a4df3c2e41c021882ee65178fe124f2a729001964624900aa0578173870fac7bfac26bb474e530261a561a9082e267dfc8d4a48c3a3adc8
7
- data.tar.gz: 84a6120026334a68f175c8fba73ddee4720d9d6913b52ef36cfc797409543a444419000d3a687843ee57cd1ad264523f761b2988984a74137079b67f413bb396
6
+ metadata.gz: d2bebaf3939fd7958b8e64fbe0cf27a397734093dda12143d5ee5fce28efc66cb199260b4e6e2f907e135f62be418df4952ec188478e1f1a6683fedcdd7527e1
7
+ data.tar.gz: 74a3f24690f3871be28af866deb5913e664ef71d8ae194e88d1f4883c09415dfa81430267fa8db42bd71b48709ee7229edf6315a00029d32c8bdbb4ee0f36720
data/.rubocop.yml CHANGED
@@ -1,5 +1,5 @@
1
1
  AllCops:
2
- TargetRubyVersion: 2.7
2
+ TargetRubyVersion: 3.0
3
3
 
4
4
  Style/StringLiterals:
5
5
  Enabled: false
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.7.6
1
+ 3.0.6
@@ -6,8 +6,11 @@
6
6
  "gsub",
7
7
  "inet",
8
8
  "klass",
9
+ "lstrip",
9
10
  "rakefile",
11
+ "rstrip",
10
12
  "solargraph",
13
+ "stringio",
11
14
  "yieldparam"
12
15
  ]
13
16
  }
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
@@ -6,7 +6,6 @@ source "https://rubygems.org"
6
6
  gemspec
7
7
 
8
8
  gem 'byebug'
9
- gem 'debug'
10
9
  gem 'git'
11
10
  gem "minitest", "~> 5.0"
12
11
  gem "rake", "~> 13.0"
data/Gemfile.lock CHANGED
@@ -1,75 +1,75 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rails-annotate-solargraph (0.5.3)
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.2.3)
13
- actionpack (= 7.0.2.3)
14
- activesupport (= 7.0.2.3)
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.2.3)
18
- actionpack (= 7.0.2.3)
19
- activejob (= 7.0.2.3)
20
- activerecord (= 7.0.2.3)
21
- activestorage (= 7.0.2.3)
22
- activesupport (= 7.0.2.3)
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.2.3)
28
- actionpack (= 7.0.2.3)
29
- actionview (= 7.0.2.3)
30
- activejob (= 7.0.2.3)
31
- activesupport (= 7.0.2.3)
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.2.3)
38
- actionview (= 7.0.2.3)
39
- activesupport (= 7.0.2.3)
40
- rack (~> 2.0, >= 2.2.0)
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.2.3)
45
- actionpack (= 7.0.2.3)
46
- activerecord (= 7.0.2.3)
47
- activestorage (= 7.0.2.3)
48
- activesupport (= 7.0.2.3)
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.2.3)
52
- activesupport (= 7.0.2.3)
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.2.3)
58
- activesupport (= 7.0.2.3)
57
+ activejob (7.0.6)
58
+ activesupport (= 7.0.6)
59
59
  globalid (>= 0.3.6)
60
- activemodel (7.0.2.3)
61
- activesupport (= 7.0.2.3)
62
- activerecord (7.0.2.3)
63
- activemodel (= 7.0.2.3)
64
- activesupport (= 7.0.2.3)
65
- activestorage (7.0.2.3)
66
- actionpack (= 7.0.2.3)
67
- activejob (= 7.0.2.3)
68
- activerecord (= 7.0.2.3)
69
- activesupport (= 7.0.2.3)
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.2.3)
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.1.10)
82
+ concurrent-ruby (1.2.2)
83
83
  crass (1.0.6)
84
- debug (1.5.0)
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.10.0)
87
+ erubi (1.12.0)
91
88
  git (1.10.2)
92
89
  rchardet (~> 1.8)
93
- globalid (1.0.0)
90
+ globalid (1.1.0)
94
91
  activesupport (>= 5.0)
95
- i18n (1.10.0)
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.16.0)
99
+ loofah (2.21.3)
106
100
  crass (~> 1.0.2)
107
- nokogiri (>= 1.5.9)
108
- mail (2.7.1)
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.2.3)
116
- digest
112
+ net-imap (0.3.6)
113
+ date
117
114
  net-protocol
118
- strscan
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-protocol (0.1.3)
124
- timeout
125
- net-smtp (0.3.1)
126
- digest
119
+ net-smtp (0.3.3)
127
120
  net-protocol
128
- timeout
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.3)
140
- rack-test (1.1.0)
141
- rack (>= 1.0, < 3)
142
- rails (7.0.2.3)
143
- actioncable (= 7.0.2.3)
144
- actionmailbox (= 7.0.2.3)
145
- actionmailer (= 7.0.2.3)
146
- actionpack (= 7.0.2.3)
147
- actiontext (= 7.0.2.3)
148
- actionview (= 7.0.2.3)
149
- activejob (= 7.0.2.3)
150
- activemodel (= 7.0.2.3)
151
- activerecord (= 7.0.2.3)
152
- activestorage (= 7.0.2.3)
153
- activesupport (= 7.0.2.3)
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.2.3)
156
- rails-dom-testing (2.0.3)
157
- activesupport (>= 4.2.0)
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.4.2)
160
- loofah (~> 2.3)
161
- railties (7.0.2.3)
162
- actionpack (= 7.0.2.3)
163
- activesupport (= 7.0.2.3)
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.2.0)
209
- tzinfo (2.0.4)
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.5)
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.5.4)
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 `app/models/annotate_solargraph_schema.rb`
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
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
93
+ ### Setup
94
94
 
95
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which 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).
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 << "test"
8
- t.libs << "lib"
9
- t.test_files = FileList["test/rails/**/*_test.rb"]
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
- system 'solargraph config' unless ::File.exist? solargraph_config_file
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
- scope_line = nil
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 unless current_line_number == scope_line_number
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
- scope_line = line.strip
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, scope_line)
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
- raise Error, "`annotation_position` is incorrect! Got `#{val.inspect}`, expected a member of `#{ANNOTATION_POSITIONS.inspect}`" \
21
- unless ANNOTATION_POSITIONS.include?(val)
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 = /(^#\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))/.freeze
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(name: name, model_class: model_class, proc_parameters: proc_parameters, definition: definition)
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! { |scope| scope.name }
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 = CONFIG.schema_file? ? SCHEMA_RAILS_PATH : ::File.join(::Rails.root, MODEL_DIR, "#{klass.to_s.underscore}.rb")
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 :write [Boolean]
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 :write [Boolean]
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
- self.class.scopes[@klass]&.each do |scope|
169
- doc_string << <<~DOC
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.exists?(file_name)
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
@@ -69,6 +69,7 @@ module Rails
69
69
  end
70
70
  end
71
71
  end
72
+
72
73
  end
73
74
  end
74
75
  end
@@ -3,7 +3,7 @@
3
3
  module Rails
4
4
  module Annotate
5
5
  module Solargraph
6
- VERSION = '0.5.3'
6
+ VERSION = '0.5.5'
7
7
  end
8
8
  end
9
9
  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 ||= (::ApplicationRecord rescue ::ActiveRecord::Base).subclasses.sort_by(&:name)
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 = ">= 2.7.0"
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 'solargraph'
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.3
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: 2022-04-20 00:00:00.000000000 Z
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: solargraph
34
+ name: parser
35
35
  requirement: !ruby/object:Gem::Requirement
36
36
  requirements:
37
- - - ">="
37
+ - - "~>"
38
38
  - !ruby/object:Gem::Version
39
- version: '0'
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: '0'
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: 2.7.0
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.1.6
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