rbs_rails 0.10.1 → 0.12.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 +15 -0
- data/Gemfile.lock +1 -2
- data/README.md +3 -5
- data/lib/generators/rbs_rails/install_generator.rb +26 -0
- data/lib/rbs_rails/active_record.rb +7 -3
- data/lib/rbs_rails/util.rb +10 -1
- data/lib/rbs_rails/version.rb +1 -1
- data/sig/_internal/thor.rbs +5 -0
- data/sig/install_generator.rbs +5 -0
- data/sig/rbs_rails/active_record.rbs +2 -0
- metadata +8 -5
- /data/sig/{activerecord.rbs → _internal/activerecord.rbs} +0 -0
- /data/sig/{fileutils.rbs → _internal/fileutils.rbs} +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cb24ff75184c9065e46c16a3dc7b5822320255c0d7045ac82dae766b753c6638
|
4
|
+
data.tar.gz: 23ed2ffdbfe910c0140610016b2a6d7671a99a6bc72e569c03dfd77b9418e78f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9f3c61ac885a8a3a8c607a9452ac21ce216a77aec13a84a2e77ec9285fdfcb4c7e43a6ff712825d538c297e29c611fad4978ef0cdebdca166c042dfb6cab8a2d
|
7
|
+
data.tar.gz: 2301cbe92bf518435e5f4323e3cc5bfbba5a4b01bfe6511916bdbfbb8f2a034421e41dc90f61035e8db8dad3bffc0108454ca62c7cf380edee967aa3ba35694e
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,21 @@
|
|
2
2
|
|
3
3
|
## master (unreleased)
|
4
4
|
|
5
|
+
## 0.12.0
|
6
|
+
|
7
|
+
* Support RBS v3. [#246](https://github.com/pocke/rbs_rails/pull/246)
|
8
|
+
* Ignore `_scope` as enum field name. [#249](https://github.com/pocke/rbs_rails/pull/249)
|
9
|
+
|
10
|
+
## 0.11.0 (2022-03-24)
|
11
|
+
|
12
|
+
### New Features
|
13
|
+
|
14
|
+
* Add rails generator to generate rbs.rake. [#217](https://github.com/pocke/rbs_rails/pull/217)
|
15
|
+
|
16
|
+
### Bug Fixes
|
17
|
+
|
18
|
+
* Do not expose polyfil RBSs. [#218](https://github.com/pocke/rbs_rails/pull/218)
|
19
|
+
|
5
20
|
## 0.10.1 (2022-03-23)
|
6
21
|
|
7
22
|
### Bug Fixes
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -20,12 +20,10 @@ Or install it yourself as:
|
|
20
20
|
|
21
21
|
## Usage
|
22
22
|
|
23
|
-
|
23
|
+
Run the following command. It generates `lib/tasks/rbs.rake`.
|
24
24
|
|
25
|
-
```
|
26
|
-
|
27
|
-
|
28
|
-
RbsRails::RakeTask.new
|
25
|
+
```console
|
26
|
+
$ bin/rails g rbs_rails:install
|
29
27
|
```
|
30
28
|
|
31
29
|
Then, the following three tasks are available.
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'rails'
|
2
|
+
|
3
|
+
module RbsRails
|
4
|
+
class InstallGenerator < Rails::Generators::Base
|
5
|
+
def create_raketask
|
6
|
+
create_file "lib/tasks/rbs.rake", <<~RUBY
|
7
|
+
require 'rbs_rails/rake_task'
|
8
|
+
|
9
|
+
RbsRails::RakeTask.new do |task|
|
10
|
+
# If you want to avoid generating RBS for some classes, comment in it.
|
11
|
+
# default: nil
|
12
|
+
#
|
13
|
+
# task.ignore_model_if = -> (klass) { klass == MyClass }
|
14
|
+
|
15
|
+
# If you want to change the rake task namespace, comment in it.
|
16
|
+
# default: :rbs_rails
|
17
|
+
# task.name = :cool_rbs_rails
|
18
|
+
|
19
|
+
# If you want to change where RBS Rails writes RBSs into, comment in it.
|
20
|
+
# default: Rails.root / 'sig/rbs_rails'
|
21
|
+
# task.signature_root_dir = Rails.root / 'my_sig/rbs_rails'
|
22
|
+
end
|
23
|
+
RUBY
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -12,6 +12,8 @@ module RbsRails
|
|
12
12
|
end
|
13
13
|
|
14
14
|
class Generator
|
15
|
+
IGNORED_ENUM_KEYS = %i[_prefix _suffix _default _scopes]
|
16
|
+
|
15
17
|
def initialize(klass, dependencies:)
|
16
18
|
@klass = klass
|
17
19
|
@dependencies = dependencies
|
@@ -159,11 +161,13 @@ module RbsRails
|
|
159
161
|
klass.reflect_on_all_associations(:belongs_to).map do |a|
|
160
162
|
@dependencies << a.klass.name unless a.polymorphic?
|
161
163
|
|
164
|
+
is_optional = a.options[:optional]
|
165
|
+
|
162
166
|
type = a.polymorphic? ? 'untyped' : Util.module_name(a.klass)
|
163
167
|
type_optional = optional(type)
|
164
168
|
# @type var methods: Array[String]
|
165
169
|
methods = []
|
166
|
-
methods << "def #{a.name}: () -> #{type}"
|
170
|
+
methods << "def #{a.name}: () -> #{is_optional ? type_optional : type}"
|
167
171
|
methods << "def #{a.name}=: (#{type_optional}) -> #{type_optional}"
|
168
172
|
methods << "def reload_#{a.name}: () -> #{type_optional}"
|
169
173
|
if !a.polymorphic?
|
@@ -316,7 +320,7 @@ module RbsRails
|
|
316
320
|
methods = []
|
317
321
|
enum_definitions.each do |hash|
|
318
322
|
hash.each do |name, values|
|
319
|
-
next if name
|
323
|
+
next if IGNORED_ENUM_KEYS.include?(name)
|
320
324
|
|
321
325
|
values.each do |label, value|
|
322
326
|
value_method_name = enum_method_name(hash, name, label)
|
@@ -334,7 +338,7 @@ module RbsRails
|
|
334
338
|
methods = []
|
335
339
|
enum_definitions.each do |hash|
|
336
340
|
hash.each do |name, values|
|
337
|
-
next if name
|
341
|
+
next if IGNORED_ENUM_KEYS.include?(name)
|
338
342
|
|
339
343
|
values.each do |label, value|
|
340
344
|
value_method_name = enum_method_name(hash, name, label)
|
data/lib/rbs_rails/util.rb
CHANGED
@@ -16,7 +16,16 @@ module RbsRails
|
|
16
16
|
end
|
17
17
|
|
18
18
|
def format_rbs(rbs)
|
19
|
-
decls =
|
19
|
+
decls =
|
20
|
+
if Gem::Version.new('3') <= Gem::Version.new(RBS::VERSION)
|
21
|
+
# TODO: Remove this type annotation when rbs_rails depends on RBS v3
|
22
|
+
# @type var parsed: [RBS::Buffer, untyped, RBS::Declarations::t]
|
23
|
+
parsed = _ = RBS::Parser.parse_signature(rbs)
|
24
|
+
parsed[1] + parsed[2]
|
25
|
+
else
|
26
|
+
RBS::Parser.parse_signature(rbs)
|
27
|
+
end
|
28
|
+
|
20
29
|
StringIO.new.tap do |io|
|
21
30
|
RBS::Writer.new(out: io).write(decls)
|
22
31
|
end.string
|
data/lib/rbs_rails/version.rb
CHANGED
@@ -7,6 +7,8 @@ class RbsRails::ActiveRecord::Generator
|
|
7
7
|
@parse_model_file: nil | Parser::AST::Node
|
8
8
|
@dependencies: Array[String]
|
9
9
|
|
10
|
+
IGNORED_ENUM_KEYS: Array[Symbol]
|
11
|
+
|
10
12
|
def initialize: (singleton(ActiveRecord::Base) klass, dependencies: Array[String]) -> untyped
|
11
13
|
|
12
14
|
def generate: () -> String
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rbs_rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.12.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Masataka Pocke Kuwabara
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-04-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: parser
|
@@ -63,6 +63,7 @@ files:
|
|
63
63
|
- bin/rbs-prototype-rb.rb
|
64
64
|
- bin/setup
|
65
65
|
- bin/to-ascii.rb
|
66
|
+
- lib/generators/rbs_rails/install_generator.rb
|
66
67
|
- lib/rbs_rails.rb
|
67
68
|
- lib/rbs_rails/active_record.rb
|
68
69
|
- lib/rbs_rails/dependency_builder.rb
|
@@ -73,8 +74,10 @@ files:
|
|
73
74
|
- rbs_collection.lock.yaml
|
74
75
|
- rbs_collection.yaml
|
75
76
|
- rbs_rails.gemspec
|
76
|
-
- sig/activerecord.rbs
|
77
|
-
- sig/fileutils.rbs
|
77
|
+
- sig/_internal/activerecord.rbs
|
78
|
+
- sig/_internal/fileutils.rbs
|
79
|
+
- sig/_internal/thor.rbs
|
80
|
+
- sig/install_generator.rbs
|
78
81
|
- sig/parser.rbs
|
79
82
|
- sig/rake.rbs
|
80
83
|
- sig/rbs_rails.rbs
|
@@ -106,7 +109,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
106
109
|
- !ruby/object:Gem::Version
|
107
110
|
version: '0'
|
108
111
|
requirements: []
|
109
|
-
rubygems_version: 3.
|
112
|
+
rubygems_version: 3.5.0.dev
|
110
113
|
signing_key:
|
111
114
|
specification_version: 4
|
112
115
|
summary: A RBS files generator for Rails application
|
File without changes
|
File without changes
|