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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 66770df53a677c589c39cfd828149a60b4ef261979e11cc7dc823a1df475495f
4
- data.tar.gz: 88de9ae8cc7597b4e28978f9a72a696742a5ece83b4d401fed92061fdd2b1590
3
+ metadata.gz: cb24ff75184c9065e46c16a3dc7b5822320255c0d7045ac82dae766b753c6638
4
+ data.tar.gz: 23ed2ffdbfe910c0140610016b2a6d7671a99a6bc72e569c03dfd77b9418e78f
5
5
  SHA512:
6
- metadata.gz: e76c5de12b626f50db6f7e032dc323de1c79067a3cb9f8e0c4e3ba5ebd71d30d4e1679144573b3eec2788d75edd33b4ff084c5ffb7ccb8839f2293e5f061595e
7
- data.tar.gz: b259952abf7664a8335a8cebda843e869a1b38c27fa010d0a927134aa56d11d63e4df20ce3850c9c2d12f62228593bd14f75ff95b7f782d00dc90d19610e71c1
6
+ metadata.gz: 9f3c61ac885a8a3a8c607a9452ac21ce216a77aec13a84a2e77ec9285fdfcb4c7e43a6ff712825d538c297e29c611fad4978ef0cdebdca166c042dfb6cab8a2d
7
+ data.tar.gz: 2301cbe92bf518435e5f4323e3cc5bfbba5a4b01bfe6511916bdbfbb8f2a034421e41dc90f61035e8db8dad3bffc0108454ca62c7cf380edee967aa3ba35694e
data/CHANGELOG.md CHANGED
@@ -2,6 +2,11 @@
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
+
5
10
  ## 0.11.0 (2022-03-24)
6
11
 
7
12
  ### New Features
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rbs_rails (0.11.0)
4
+ rbs_rails (0.12.0)
5
5
  parser
6
6
  rbs (>= 1)
7
7
 
@@ -163,7 +163,6 @@ GEM
163
163
 
164
164
  PLATFORMS
165
165
  ruby
166
- x86_64-linux
167
166
 
168
167
  DEPENDENCIES
169
168
  minitest
@@ -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 == :_prefix || name == :_suffix || name == :_default
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 == :_prefix || name == :_suffix || name == :_default
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)
@@ -16,7 +16,16 @@ module RbsRails
16
16
  end
17
17
 
18
18
  def format_rbs(rbs)
19
- decls = RBS::Parser.parse_signature(rbs)
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
@@ -2,5 +2,5 @@ module RbsRails
2
2
  # Because of copy_signatures is defined by lib/rbs_rails.rb
3
3
  # @dynamic self.copy_signatures
4
4
 
5
- VERSION = "0.11.0"
5
+ VERSION = "0.12.0"
6
6
  end
@@ -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.11.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: 2022-03-24 00:00:00.000000000 Z
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.4.0.dev
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