rails-annotate-solargraph 0.2.3 → 0.3.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 +4 -4
- data/CHANGELOG.md +6 -0
- data/Gemfile.lock +1 -1
- data/lib/rails/annotate/solargraph/model.rb +123 -18
- 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,9 @@
|
|
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
|
+
|
3
7
|
## [0.2.3] - 2022-04-16
|
4
8
|
|
5
9
|
- A nicer fix for the previous problem
|
@@ -15,6 +19,7 @@
|
|
15
19
|
## [0.2.0] - 2022-04-16
|
16
20
|
|
17
21
|
- Associations get fully documented
|
22
|
+
- `has_many`, `has_one` and `belongs_to` relations get documented
|
18
23
|
|
19
24
|
## [0.1.1] - 2022-04-15
|
20
25
|
|
@@ -24,4 +29,5 @@
|
|
24
29
|
|
25
30
|
- Initial release
|
26
31
|
- Automatic generation of annotations after migrations
|
32
|
+
- Database fields get documented
|
27
33
|
- Manual rake tasks `annotate:solargraph:generate`, `annotate:solargraph:remove`
|
data/Gemfile.lock
CHANGED
@@ -142,37 +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
|
-
|
151
|
-
|
152
|
-
rescue ::NameError
|
153
|
-
Object
|
154
|
-
end
|
155
|
-
|
156
|
-
associated_table_name = reflection_class.try(:table_name) || '<unknown>'
|
157
|
-
foreign_key = reflection.try(:foreign_key) || '<unknown>'
|
158
|
-
db_description = \
|
170
|
+
reflection_klass = reflection_class(reflection)
|
171
|
+
type_docstring, db_description = \
|
159
172
|
case reflection
|
160
173
|
when ::ActiveRecord::Reflection::BelongsToReflection
|
161
|
-
|
162
|
-
|
174
|
+
belongs_to_description(reflection_klass,
|
175
|
+
class_table_name(@klass),
|
176
|
+
reflection_foreign_key(reflection))
|
163
177
|
when ::ActiveRecord::Reflection::HasOneReflection
|
164
|
-
|
165
|
-
|
178
|
+
has_one_description(reflection_klass,
|
179
|
+
class_table_name(reflection_klass),
|
180
|
+
reflection_foreign_key(reflection))
|
166
181
|
when ::ActiveRecord::Reflection::HasManyReflection
|
167
|
-
|
168
|
-
|
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, '']
|
169
189
|
end
|
170
190
|
|
171
191
|
doc_string << <<~DOC
|
172
|
-
#
|
192
|
+
# ##{db_description}
|
173
193
|
# # @param val [#{type_docstring}, nil]
|
174
194
|
# def #{attr_name}=(val); end
|
175
|
-
#
|
195
|
+
# ##{db_description}
|
176
196
|
# # @return [#{type_docstring}, nil]
|
177
197
|
# def #{attr_name}; end
|
178
198
|
DOC
|
@@ -187,7 +207,7 @@ module Rails
|
|
187
207
|
model_class.reflections[klass_relation_name]&.options&.[](:as)&.to_sym == attr_name.to_sym
|
188
208
|
end
|
189
209
|
|
190
|
-
classes_string = classes.join(', ')
|
210
|
+
classes_string = classes.empty? ? ::Object.to_s : classes.join(', ')
|
191
211
|
doc_string << <<~DOC
|
192
212
|
# # Polymorphic relation. Database columns `#{@klass.table_name}.#{attr_name}_id` and `#{@klass.table_name}.#{attr_name}_type`.
|
193
213
|
# # @param val [#{classes_string}, nil]
|
@@ -198,6 +218,91 @@ module Rails
|
|
198
218
|
DOC
|
199
219
|
end
|
200
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
|
+
|
201
306
|
# @param attr_type [ActiveModel::Type::Value]
|
202
307
|
# @return [String]
|
203
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:
|