rails-annotate-solargraph 0.4.0 → 0.5.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 80d2fcb8fc2090d6a1eabc8f510b3b9fec1608da1870c7d88b301ce64907920a
4
- data.tar.gz: 9553090d359f8f829e955349cac6c527c43335433e38d91152862780cce3ab63
3
+ metadata.gz: 641aad34ff5a1a7f98a1eca52baf74c311308b2e9e062cf8c5ac3c0186d1f1ec
4
+ data.tar.gz: 70657a49775862f8b50dc2e04f7b489b04f124cbfb4893f777f5a11f69b0ba51
5
5
  SHA512:
6
- metadata.gz: 8b2415d929d939454a4f65277d85baa03935219226c6ad5b35c35264cd2de94bb1b1d55a55a55ee8cc737523210e3653c648bea50798dd53b580767fbb6a2eec
7
- data.tar.gz: 9436e870a6cbc28e636151b76717cde5bf4186f44bc8af4293ada785f1c50e039895fcf5cb38dd27868c5e88027df9f52be8ee070591e0635de30fdba7437aef
6
+ metadata.gz: 8a2c58e2d0dbb0dd0df66d1f2f04242095081c4159059c8830021cc16f9ece5222dc9fee73392757b88cf1798f5e53256a09fc2291585b8474c36db8777d64f2
7
+ data.tar.gz: 6335dab053b82ff232fdcc69c3453eea68ae44432bd6f4032f29ab812072e9053795955556f14578479bd47ebd37a3bfc6ac592254de63801d38369834dcc358
@@ -1,6 +1,10 @@
1
1
  {
2
2
  "cSpell.words": [
3
3
  "activerecord",
4
+ "citext",
5
+ "datetime",
6
+ "gsub",
7
+ "inet",
4
8
  "klass",
5
9
  "rakefile",
6
10
  "solargraph",
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,8 +1,10 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rails-annotate-solargraph (0.4.0)
4
+ rails-annotate-solargraph (0.5.0)
5
5
  rails (>= 5.0, < 8.0)
6
+ solargraph
7
+ yard
6
8
 
7
9
  GEM
8
10
  remote: https://rubygems.org/
@@ -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
@@ -19,6 +19,7 @@ if ::Rails.env.development?
19
19
  next unless ::Rake::Task.task_defined?(task)
20
20
 
21
21
  ::Rake::Task[task].enhance do
22
+ system 'yard gems' unless ENV['TEST']
22
23
  ::Rake::Task['annotate:solargraph:generate'].invoke
23
24
  end
24
25
  end
@@ -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
- class << self
15
- # @param type [Symbol, String, nil]
16
- # @return [String]
17
- def active_record_type_to_yard(type)
18
- case type&.to_sym
19
- when :float
20
- ::Float.to_s
21
- when :integer
22
- ::Integer.to_s
23
- when :decimal
24
- ::BigDecimal.to_s
25
- when :datetime, :timestamp, :time
26
- ::Time.to_s
27
- when :json, :jsonb
28
- ::Hash.to_s
29
- when :date
30
- ::Date.to_s
31
- when :text, :string, :binary, :inet, :uuid
32
- ::String.to_s
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
- base_file_name = CONFIG.schema_file? ? SCHEMA_FILE_NAME : "#{klass.to_s.underscore}.rb"
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
- # @!parse
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
- self.class.active_record_type_to_yard(attr_type.type)
352
+ TYPE_MAP[attr_type.type]
348
353
  end
349
354
  end
350
355
  end
@@ -3,7 +3,7 @@
3
3
  module Rails
4
4
  module Annotate
5
5
  module Solargraph
6
- VERSION = '0.4.0'
6
+ VERSION = '0.5.0'
7
7
  end
8
8
  end
9
9
  end
@@ -23,7 +23,11 @@ module Rails
23
23
  # @return [String]
24
24
  SCHEMA_CLASS_NAME = 'AnnotateSolargraphSchema'
25
25
  # @return [String]
26
- SCHEMA_FILE_NAME = "annotate_solargraph_schema.rb"
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(::Rails.root, MODEL_DIR, SCHEMA_FILE_NAME)
60
- return unless CONFIG.schema_file? && !::File.exist?(schema_file)
63
+ schema_file = ::File.join ::Rails.root, SCHEMA_RAILS_PATH
64
+ return if ::File.exist?(schema_file)
61
65
 
62
- ::FileUtils.touch(schema_file)
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.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-17 00:00:00.000000000 Z
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