rails-annotate-solargraph 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.vscode/settings.json +4 -0
- data/CHANGELOG.md +8 -0
- data/Gemfile.lock +3 -1
- data/lib/generators/annotate/solargraph/install_generator.rb +16 -0
- data/lib/generators/annotate/solargraph/templates/.annotate_solargraph_schema +69 -0
- data/lib/generators/annotate/solargraph/templates/rails_annotate_solargraph.rake +1 -0
- data/lib/rails/annotate/solargraph/model.rb +34 -29
- data/lib/rails/annotate/solargraph/version.rb +1 -1
- data/lib/rails/annotate/solargraph.rb +8 -7
- data/rails-annotate-solargraph.gemspec +2 -0
- metadata +31 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 641aad34ff5a1a7f98a1eca52baf74c311308b2e9e062cf8c5ac3c0186d1f1ec
|
4
|
+
data.tar.gz: 70657a49775862f8b50dc2e04f7b489b04f124cbfb4893f777f5a11f69b0ba51
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8a2c58e2d0dbb0dd0df66d1f2f04242095081c4159059c8830021cc16f9ece5222dc9fee73392757b88cf1798f5e53256a09fc2291585b8474c36db8777d64f2
|
7
|
+
data.tar.gz: 6335dab053b82ff232fdcc69c3453eea68ae44432bd6f4032f29ab812072e9053795955556f14578479bd47ebd37a3bfc6ac592254de63801d38369834dcc358
|
data/.vscode/settings.json
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,13 @@
|
|
1
1
|
## [Unreleased]
|
2
2
|
|
3
|
+
## [0.5.0] - 2022-04-19
|
4
|
+
|
5
|
+
- Add some static comments to the schema file to improve general Rails intellisense
|
6
|
+
- Rename schema file from `app/models/annotate_solargraph_schema.rb` to `.annotate-solargraph-schema`
|
7
|
+
- Generate schema file as a regular ruby file
|
8
|
+
- Add `yard` and `solargraph` as dependencies
|
9
|
+
- Add `.solargraph.yml` to the installation generator
|
10
|
+
|
3
11
|
## [0.4.0] - 2022-04-17
|
4
12
|
|
5
13
|
- Annotations get saved to a schema file by default `app/models/annotate_solargraph_schema.rb`
|
data/Gemfile.lock
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'yaml'
|
4
|
+
require 'set'
|
5
|
+
|
1
6
|
module Annotate
|
2
7
|
module Solargraph
|
3
8
|
module Generators
|
@@ -8,6 +13,17 @@ module Annotate
|
|
8
13
|
# copy rake tasks
|
9
14
|
def copy_tasks
|
10
15
|
template ::Rails::Annotate::Solargraph::RAKEFILE_NAME, ::File.join('lib', 'tasks', ::Rails::Annotate::Solargraph::RAKEFILE_NAME)
|
16
|
+
template ::Rails::Annotate::Solargraph::SCHEMA_FILE_NAME, ::Rails::Annotate::Solargraph::SCHEMA_RAILS_PATH
|
17
|
+
|
18
|
+
solargraph_config_file = ::File.join(::Rails.root, ::Rails::Annotate::Solargraph::SOLARGRAPH_FILE_NAME)
|
19
|
+
system 'solargraph config' unless ::File.exist? solargraph_config_file
|
20
|
+
solargraph_config = ::YAML.load_file solargraph_config_file
|
21
|
+
solargraph_config['include'] = solargraph_config['include'] || []
|
22
|
+
solargraph_config['include'].unshift ::Rails::Annotate::Solargraph::SCHEMA_RAILS_PATH
|
23
|
+
# make sure there are no duplicated entries
|
24
|
+
solargraph_config['include'] = solargraph_config['include'].to_set.to_a
|
25
|
+
|
26
|
+
::File.write(solargraph_config_file, solargraph_config.to_yaml)
|
11
27
|
end
|
12
28
|
end
|
13
29
|
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
# This is a dummy file generated by `rails-annotate-solargraph`
|
2
|
+
# to extend solargraph's understanding of your Rails app.
|
3
|
+
# You should probably add it to `.gitignore`
|
4
|
+
|
5
|
+
# Some static comments to fill a few gaps
|
6
|
+
# in Rails comprehension.
|
7
|
+
|
8
|
+
class ActionController::Base
|
9
|
+
include ActionController::MimeResponds
|
10
|
+
include ActionController::Redirecting
|
11
|
+
include ActionController::Cookies
|
12
|
+
include AbstractController::Rendering
|
13
|
+
extend ActiveSupport::Callbacks::ClassMethods
|
14
|
+
extend ActiveSupport::Rescuable::ClassMethods
|
15
|
+
extend AbstractController::Callbacks::ClassMethods
|
16
|
+
extend ActionController::RequestForgeryProtection::ClassMethods
|
17
|
+
end
|
18
|
+
class ActiveRecord::Base
|
19
|
+
extend ActiveRecord::Reflection::ClassMethods
|
20
|
+
extend ActiveModel::SecurePassword::ClassMethods
|
21
|
+
extend ActiveModel::Attributes::ClassMethods
|
22
|
+
include ActiveModel::Attributes
|
23
|
+
include ActiveModel::Dirty
|
24
|
+
extend ActiveRecord::Validations::ClassMethods
|
25
|
+
include ActiveRecord::Validations
|
26
|
+
extend ActiveModel::Validations::ClassMethods
|
27
|
+
include ActiveModel::Validations
|
28
|
+
extend ActiveRecord::Calculations
|
29
|
+
extend ActiveRecord::Batches
|
30
|
+
extend ActiveRecord::QueryMethods
|
31
|
+
extend ActiveRecord::FinderMethods
|
32
|
+
extend ActiveRecord::Associations::ClassMethods
|
33
|
+
extend ActiveRecord::Inheritance::ClassMethods
|
34
|
+
extend ActiveRecord::ModelSchema::ClassMethods
|
35
|
+
extend ActiveRecord::Transactions::ClassMethods
|
36
|
+
extend ActiveRecord::Scoping::Named::ClassMethods
|
37
|
+
include ActiveRecord::Persistence
|
38
|
+
|
39
|
+
<% (ActiveRecord::Callbacks::CALLBACKS rescue []).each do |callback| -%>
|
40
|
+
# Registers a callback to be called <%= callback.to_s.gsub('_', ' ') %>.
|
41
|
+
# See `ActiveRecord::Callbacks` for more information.
|
42
|
+
# @return [void]
|
43
|
+
def self.<%= callback %>(*args, &block); end
|
44
|
+
<% end -%>
|
45
|
+
|
46
|
+
end
|
47
|
+
class Rails
|
48
|
+
# @return [Rails::Application]
|
49
|
+
def self.application; end
|
50
|
+
end
|
51
|
+
class Rails::Application
|
52
|
+
# @return [ActionDispatch::Routing::RouteSet]
|
53
|
+
def routes; end
|
54
|
+
end
|
55
|
+
class ActionDispatch::Routing::Mapper
|
56
|
+
include ActionDispatch::Routing::Mapper::Base
|
57
|
+
include ActionDispatch::Routing::Mapper::HttpHelpers
|
58
|
+
include ActionDispatch::Routing::Mapper::Redirection
|
59
|
+
include ActionDispatch::Routing::Mapper::Scoping
|
60
|
+
include ActionDispatch::Routing::Mapper::Concerns
|
61
|
+
include ActionDispatch::Routing::Mapper::Resources
|
62
|
+
include ActionDispatch::Routing::Mapper::CustomUrls
|
63
|
+
end
|
64
|
+
class ActionDispatch::Routing::RouteSet
|
65
|
+
# @yieldself [ActionDispatch::Routing::Mapper]
|
66
|
+
def draw; end
|
67
|
+
end
|
68
|
+
|
69
|
+
# Dynamically generated documentation
|
@@ -11,32 +11,27 @@ module Rails
|
|
11
11
|
# @return [Regexp]
|
12
12
|
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
|
13
13
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
when :boolean
|
34
|
-
'Boolean'
|
35
|
-
else
|
36
|
-
::Object.to_s
|
37
|
-
end
|
38
|
-
end
|
14
|
+
# @return [Hash{Symbol => String}]
|
15
|
+
TYPE_MAP = {
|
16
|
+
float: 'BigDecimal',
|
17
|
+
decimal: 'BigDecimal',
|
18
|
+
integer: 'Integer',
|
19
|
+
datetime: 'ActiveSupport::TimeWithZone',
|
20
|
+
date: 'Date',
|
21
|
+
string: 'String',
|
22
|
+
boolean: 'Boolean',
|
23
|
+
text: 'String',
|
24
|
+
jsonb: 'Hash',
|
25
|
+
citext: 'String',
|
26
|
+
json: 'Hash',
|
27
|
+
bigint: 'Integer',
|
28
|
+
uuid: 'String',
|
29
|
+
inet: 'IPAddr'
|
30
|
+
}
|
31
|
+
TYPE_MAP.default = 'Object'
|
32
|
+
TYPE_MAP.freeze
|
39
33
|
|
34
|
+
class << self
|
40
35
|
# @param klass [Class]
|
41
36
|
# @return [String]
|
42
37
|
def annotation_start(klass = nil)
|
@@ -67,8 +62,7 @@ module Rails
|
|
67
62
|
# @param klass [Class]
|
68
63
|
def initialize(klass)
|
69
64
|
@klass = klass
|
70
|
-
|
71
|
-
@file_name = ::File.join(::Rails.root, MODEL_DIR, base_file_name)
|
65
|
+
@file_name = CONFIG.schema_file? ? SCHEMA_RAILS_PATH : ::File.join(::Rails.root, MODEL_DIR, "#{klass.to_s.underscore}.rb")
|
72
66
|
end
|
73
67
|
|
74
68
|
# @return [String]
|
@@ -128,7 +122,7 @@ module Rails
|
|
128
122
|
doc_string = ::String.new
|
129
123
|
doc_string << <<~DOC
|
130
124
|
#{annotation_start}
|
131
|
-
|
125
|
+
##{parse_clause}
|
132
126
|
# class #{@klass} < #{@klass.superclass}
|
133
127
|
DOC
|
134
128
|
|
@@ -153,10 +147,21 @@ module Rails
|
|
153
147
|
# end
|
154
148
|
# #{annotation_end}
|
155
149
|
DOC
|
150
|
+
|
151
|
+
# uncomment the generated annotations if they're saved in the schema file
|
152
|
+
return doc_string.gsub(/^#\ {3}/, '').gsub(/^#\n/, "\n") if CONFIG.schema_file?
|
153
|
+
|
154
|
+
doc_string
|
156
155
|
end
|
157
156
|
|
158
157
|
private
|
159
158
|
|
159
|
+
def parse_clause
|
160
|
+
return if CONFIG.schema_file?
|
161
|
+
|
162
|
+
" @!parse\n#"
|
163
|
+
end
|
164
|
+
|
160
165
|
# @param file_name [String]
|
161
166
|
# @return [String]
|
162
167
|
def relative_file_name(file_name)
|
@@ -344,7 +349,7 @@ module Rails
|
|
344
349
|
return attr_type.coder.object_class.to_s if attr_type.respond_to?(:coder) && attr_type.coder.respond_to?(:object_class)
|
345
350
|
return 'Object' if attr_type.respond_to?(:coder) && attr_type.coder.is_a?(::ActiveRecord::Coders::JSON)
|
346
351
|
|
347
|
-
|
352
|
+
TYPE_MAP[attr_type.type]
|
348
353
|
end
|
349
354
|
end
|
350
355
|
end
|
@@ -23,7 +23,11 @@ module Rails
|
|
23
23
|
# @return [String]
|
24
24
|
SCHEMA_CLASS_NAME = 'AnnotateSolargraphSchema'
|
25
25
|
# @return [String]
|
26
|
-
|
26
|
+
SOLARGRAPH_FILE_NAME = '.solargraph.yml'
|
27
|
+
# @return [String]
|
28
|
+
SCHEMA_FILE_NAME = '.annotate_solargraph_schema'
|
29
|
+
# @return [String]
|
30
|
+
SCHEMA_RAILS_PATH = SCHEMA_FILE_NAME
|
27
31
|
|
28
32
|
class << self
|
29
33
|
# @return [Array<String>] Array of changed files.
|
@@ -56,13 +60,10 @@ module Rails
|
|
56
60
|
include TerminalColors
|
57
61
|
|
58
62
|
def create_schema_file
|
59
|
-
schema_file = ::File.join
|
60
|
-
return
|
63
|
+
schema_file = ::File.join ::Rails.root, SCHEMA_RAILS_PATH
|
64
|
+
return if ::File.exist?(schema_file)
|
61
65
|
|
62
|
-
|
63
|
-
::File.write schema_file, <<~SCHEMA
|
64
|
-
module AnnotateSolargraphSchema; end
|
65
|
-
SCHEMA
|
66
|
+
system 'rails g annotate:solargraph:install'
|
66
67
|
end
|
67
68
|
|
68
69
|
# @param method [Symbol] Name of the method that will be called on every loaded Model
|
@@ -31,6 +31,8 @@ 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'
|
35
|
+
spec.add_dependency 'yard'
|
34
36
|
|
35
37
|
# For more information and examples about making a new gem, check out our
|
36
38
|
# guide at: https://bundler.io/guides/creating_gem.html
|
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.5.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-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -30,6 +30,34 @@ dependencies:
|
|
30
30
|
- - "<"
|
31
31
|
- !ruby/object:Gem::Version
|
32
32
|
version: '8.0'
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: solargraph
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
type: :runtime
|
41
|
+
prerelease: false
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: yard
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '0'
|
33
61
|
description: Annotate ActiveRecord models with schema comments formatted in YARD that
|
34
62
|
are compatible with Solargraph.
|
35
63
|
email:
|
@@ -53,6 +81,7 @@ files:
|
|
53
81
|
- bin/console
|
54
82
|
- bin/setup
|
55
83
|
- lib/generators/annotate/solargraph/install_generator.rb
|
84
|
+
- lib/generators/annotate/solargraph/templates/.annotate_solargraph_schema
|
56
85
|
- lib/generators/annotate/solargraph/templates/rails_annotate_solargraph.rake
|
57
86
|
- lib/rails/annotate/solargraph.rb
|
58
87
|
- lib/rails/annotate/solargraph/configuration.rb
|