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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 16dd1379f4621410d78e352c8fdc8750d3fb469d8c395aee77de85d2f8570279
4
- data.tar.gz: e50b75cc1e64a8630c1508805d146d2cf5edad065cdcab502f910fcb84bc51ef
3
+ metadata.gz: cb24ff75184c9065e46c16a3dc7b5822320255c0d7045ac82dae766b753c6638
4
+ data.tar.gz: 23ed2ffdbfe910c0140610016b2a6d7671a99a6bc72e569c03dfd77b9418e78f
5
5
  SHA512:
6
- metadata.gz: 12136882eeebf0e2219af85c6393f6b8a74c4bc6f268b57d5b9c931a99fa42ee81ed9deb9885d4209f28dbf43d9d57563641379031c199397cf520a7dc417f10
7
- data.tar.gz: 40ffd8a1525501f736f759769a95183e3933da0c1063e5e939b6c4ccf23ae9d98731ef782c23f6c7eb6b7280b2c39f535379886edeb3abeb423810cf2ead58ac
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
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rbs_rails (0.10.1)
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
data/README.md CHANGED
@@ -20,12 +20,10 @@ Or install it yourself as:
20
20
 
21
21
  ## Usage
22
22
 
23
- Put the following code to `lib/tasks/rbs.rake`.
23
+ Run the following command. It generates `lib/tasks/rbs.rake`.
24
24
 
25
- ```ruby
26
- require 'rbs_rails/rake_task'
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 == :_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.10.1"
5
+ VERSION = "0.12.0"
6
6
  end
@@ -0,0 +1,5 @@
1
+ class Thor
2
+ module Actions
3
+ def create_file: (String, String) -> void
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ module RbsRails
2
+ class InstallGenerator < Rails::Generators::Base
3
+ def create_raketask: () -> void
4
+ end
5
+ 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.10.1
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-23 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
@@ -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.4.0.dev
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