rbs_rails 0.11.0 → 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 +5 -0
- data/Gemfile.lock +1 -2
- 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/rbs_rails/active_record.rbs +2 -0
- metadata +3 -3
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
data/Gemfile.lock
CHANGED
@@ -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
|
@@ -109,7 +109,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '0'
|
111
111
|
requirements: []
|
112
|
-
rubygems_version: 3.
|
112
|
+
rubygems_version: 3.5.0.dev
|
113
113
|
signing_key:
|
114
114
|
specification_version: 4
|
115
115
|
summary: A RBS files generator for Rails application
|