rails-annotate-solargraph 0.2.1 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +14 -0
- data/Gemfile.lock +1 -1
- data/lib/rails/annotate/solargraph/model.rb +123 -10
- data/lib/rails/annotate/solargraph/version.rb +1 -1
- data/rails-annotate-solargraph.gemspec +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4ca6f0073923760a583abb52af713540b2f53cf6e8dd896584e3a76b97444c8b
|
4
|
+
data.tar.gz: a07141ca737ee0c60153cabd5e28540d3507ba09401b4cc31d30ea491bc32eb2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f3a40df235de87414059053670f344e0e6606b9538ecba40b7fbb2c849c07f8009e5cec055e485033bae5529bce9146d2369d76b8a6ab4288664703bef29da2f
|
7
|
+
data.tar.gz: d920e8b59c64f57d22fba128b4db1acffd88b718799e24e2f361d43e99ae6505258faa2665f57fafdee9d9cd6d4dc47231c9e5e7bb99a7e687707c2642e211e5
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,17 @@
|
|
1
1
|
## [Unreleased]
|
2
2
|
|
3
|
+
## [0.3.0] - 2022-04-17
|
4
|
+
|
5
|
+
- `has_many :through` and `has_one :through` relations get documented
|
6
|
+
|
7
|
+
## [0.2.3] - 2022-04-16
|
8
|
+
|
9
|
+
- A nicer fix for the previous problem
|
10
|
+
|
11
|
+
## [0.2.2] - 2022-04-16
|
12
|
+
|
13
|
+
- Inexistent class loading error has been resolved
|
14
|
+
|
3
15
|
## [0.2.1] - 2022-04-16
|
4
16
|
|
5
17
|
- Rakefile template refactoring and bug fix
|
@@ -7,6 +19,7 @@
|
|
7
19
|
## [0.2.0] - 2022-04-16
|
8
20
|
|
9
21
|
- Associations get fully documented
|
22
|
+
- `has_many`, `has_one` and `belongs_to` relations get documented
|
10
23
|
|
11
24
|
## [0.1.1] - 2022-04-15
|
12
25
|
|
@@ -16,4 +29,5 @@
|
|
16
29
|
|
17
30
|
- Initial release
|
18
31
|
- Automatic generation of annotations after migrations
|
32
|
+
- Database fields get documented
|
19
33
|
- Manual rake tasks `annotate:solargraph:generate`, `annotate:solargraph:remove`
|
data/Gemfile.lock
CHANGED
@@ -142,29 +142,57 @@ module Rails
|
|
142
142
|
@klass.table_name[..-2]
|
143
143
|
end
|
144
144
|
|
145
|
+
# @param reflection [ActiveRecord::Reflection::AbstractReflection]
|
146
|
+
# @return [Class]
|
147
|
+
def reflection_class(reflection)
|
148
|
+
reflection.klass
|
149
|
+
rescue ::NameError
|
150
|
+
Object
|
151
|
+
end
|
152
|
+
|
153
|
+
# @param reflection [ActiveRecord::Reflection::AbstractReflection]
|
154
|
+
# @return [String]
|
155
|
+
def reflection_foreign_key(reflection)
|
156
|
+
reflection.try(:foreign_key) || '<unknown>'
|
157
|
+
end
|
158
|
+
|
159
|
+
# @param klass [Class]
|
160
|
+
# @return [String]
|
161
|
+
def class_table_name(klass)
|
162
|
+
klass.try(:table_name) || '<unknown>'
|
163
|
+
end
|
164
|
+
|
145
165
|
# @param doc_string [String]
|
146
166
|
# @param attr_name [String]
|
147
167
|
# @param reflection [ActiveRecord::Reflection::AbstractReflection]
|
148
168
|
# @return [void]
|
149
169
|
def document_relation(doc_string, attr_name, reflection)
|
150
|
-
|
170
|
+
reflection_klass = reflection_class(reflection)
|
171
|
+
type_docstring, db_description = \
|
151
172
|
case reflection
|
152
173
|
when ::ActiveRecord::Reflection::BelongsToReflection
|
153
|
-
|
154
|
-
|
174
|
+
belongs_to_description(reflection_klass,
|
175
|
+
class_table_name(@klass),
|
176
|
+
reflection_foreign_key(reflection))
|
155
177
|
when ::ActiveRecord::Reflection::HasOneReflection
|
156
|
-
|
157
|
-
|
178
|
+
has_one_description(reflection_klass,
|
179
|
+
class_table_name(reflection_klass),
|
180
|
+
reflection_foreign_key(reflection))
|
158
181
|
when ::ActiveRecord::Reflection::HasManyReflection
|
159
|
-
|
160
|
-
|
182
|
+
has_many_description(reflection_klass,
|
183
|
+
class_table_name(reflection_klass),
|
184
|
+
reflection_foreign_key(reflection))
|
185
|
+
when ::ActiveRecord::Reflection::ThroughReflection
|
186
|
+
through_description(reflection)
|
187
|
+
else
|
188
|
+
[::Object.to_s, '']
|
161
189
|
end
|
162
190
|
|
163
191
|
doc_string << <<~DOC
|
164
|
-
#
|
192
|
+
# ##{db_description}
|
165
193
|
# # @param val [#{type_docstring}, nil]
|
166
194
|
# def #{attr_name}=(val); end
|
167
|
-
#
|
195
|
+
# ##{db_description}
|
168
196
|
# # @return [#{type_docstring}, nil]
|
169
197
|
# def #{attr_name}; end
|
170
198
|
DOC
|
@@ -179,7 +207,7 @@ module Rails
|
|
179
207
|
model_class.reflections[klass_relation_name]&.options&.[](:as)&.to_sym == attr_name.to_sym
|
180
208
|
end
|
181
209
|
|
182
|
-
classes_string = classes.join(', ')
|
210
|
+
classes_string = classes.empty? ? ::Object.to_s : classes.join(', ')
|
183
211
|
doc_string << <<~DOC
|
184
212
|
# # Polymorphic relation. Database columns `#{@klass.table_name}.#{attr_name}_id` and `#{@klass.table_name}.#{attr_name}_type`.
|
185
213
|
# # @param val [#{classes_string}, nil]
|
@@ -190,6 +218,91 @@ module Rails
|
|
190
218
|
DOC
|
191
219
|
end
|
192
220
|
|
221
|
+
# @param reflection [ActiveRecord::Reflection::AbstractReflection]
|
222
|
+
# @return [Array<String>]
|
223
|
+
def through_description(reflection)
|
224
|
+
through_klass = reflection_class(reflection.through_reflection)
|
225
|
+
|
226
|
+
case (reflection.__send__(:delegate_reflection) rescue nil)
|
227
|
+
when ::ActiveRecord::Reflection::HasOneReflection
|
228
|
+
has_one_description(reflection_class(reflection.source_reflection),
|
229
|
+
class_table_name(through_klass),
|
230
|
+
reflection_foreign_key(reflection.source_reflection),
|
231
|
+
through: through_klass)
|
232
|
+
when ::ActiveRecord::Reflection::HasManyReflection
|
233
|
+
has_many_description(reflection_class(reflection.source_reflection),
|
234
|
+
class_table_name(through_klass),
|
235
|
+
reflection_foreign_key(reflection.source_reflection),
|
236
|
+
through: through_klass)
|
237
|
+
else
|
238
|
+
[::Object.to_s, '']
|
239
|
+
end
|
240
|
+
end
|
241
|
+
|
242
|
+
# @param through [Class, nil]
|
243
|
+
# @return [String]
|
244
|
+
def through_sentence(through = nil)
|
245
|
+
return '' unless through
|
246
|
+
|
247
|
+
" through `#{through}`"
|
248
|
+
end
|
249
|
+
|
250
|
+
# @param table_name [String]
|
251
|
+
# @param foreign_key [String]
|
252
|
+
# @param through [Class, nil]
|
253
|
+
# @return [String]
|
254
|
+
def column_description(table_name, foreign_key, through = nil)
|
255
|
+
return '' if through
|
256
|
+
|
257
|
+
" Database column `#{table_name}.#{foreign_key}`."
|
258
|
+
end
|
259
|
+
|
260
|
+
# @param relation [Symbol, String]
|
261
|
+
# @param klass [Class]
|
262
|
+
# @param table_name [String]
|
263
|
+
# @param foreign_key [String]
|
264
|
+
# @param through [Class, nil]
|
265
|
+
# @return [String]
|
266
|
+
def relation_description(relation, klass, table_name, foreign_key, through = nil)
|
267
|
+
" `#{relation}` relation with `#{klass}`#{through_sentence(through)}.#{column_description(table_name, foreign_key, through)}"
|
268
|
+
end
|
269
|
+
|
270
|
+
|
271
|
+
# @param klass [Class]
|
272
|
+
# @param table_name [String]
|
273
|
+
# @param foreign_key [String]
|
274
|
+
# @param :through [Class, nil]
|
275
|
+
# @return [Array<String>] Type docstring followed by the description of the method.
|
276
|
+
def has_many_description(klass, table_name, foreign_key, through: nil)
|
277
|
+
type_docstring = "Array<#{klass}>"
|
278
|
+
desc = relation_description(:has_many, klass, table_name, foreign_key, through)
|
279
|
+
|
280
|
+
[type_docstring, desc]
|
281
|
+
end
|
282
|
+
|
283
|
+
# @param klass [Class]
|
284
|
+
# @param table_name [String]
|
285
|
+
# @param foreign_key [String]
|
286
|
+
# @param :through [Class, nil]
|
287
|
+
# @return [Array<String>] Type docstring followed by the description of the method.
|
288
|
+
def has_one_description(klass, table_name, foreign_key, through: nil)
|
289
|
+
type_docstring = klass
|
290
|
+
desc = relation_description(:has_one, klass, table_name, foreign_key, through)
|
291
|
+
|
292
|
+
[type_docstring, desc]
|
293
|
+
end
|
294
|
+
|
295
|
+
# @param klass [Class]
|
296
|
+
# @param table_name [String]
|
297
|
+
# @param foreign_key [String]
|
298
|
+
# @return [Array<String>] Type docstring followed by the description of the method.
|
299
|
+
def belongs_to_description(klass, table_name, foreign_key)
|
300
|
+
type_docstring = klass
|
301
|
+
desc = relation_description(:belongs_to, klass, table_name, foreign_key)
|
302
|
+
|
303
|
+
[type_docstring, desc]
|
304
|
+
end
|
305
|
+
|
193
306
|
# @param attr_type [ActiveModel::Type::Value]
|
194
307
|
# @return [String]
|
195
308
|
def yard_type(attr_type)
|
@@ -16,7 +16,7 @@ Gem::Specification.new do |spec|
|
|
16
16
|
|
17
17
|
spec.metadata["homepage_uri"] = spec.homepage
|
18
18
|
spec.metadata["source_code_uri"] = "https://gitlab.com/mateuszdrewniak/rails-annotate-solargraph"
|
19
|
-
|
19
|
+
spec.metadata["changelog_uri"] = "https://gitlab.com/mateuszdrewniak/rails-annotate-solargraph/-/raw/main/CHANGELOG.md"
|
20
20
|
|
21
21
|
# Specify which files should be added to the gem when it is released.
|
22
22
|
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
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.
|
4
|
+
version: 0.3.0
|
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-
|
11
|
+
date: 2022-04-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -67,6 +67,7 @@ licenses:
|
|
67
67
|
metadata:
|
68
68
|
homepage_uri: https://gitlab.com/mateuszdrewniak/rails-annotate-solargraph
|
69
69
|
source_code_uri: https://gitlab.com/mateuszdrewniak/rails-annotate-solargraph
|
70
|
+
changelog_uri: https://gitlab.com/mateuszdrewniak/rails-annotate-solargraph/-/raw/main/CHANGELOG.md
|
70
71
|
post_install_message:
|
71
72
|
rdoc_options: []
|
72
73
|
require_paths:
|