rbs_activerecord 1.1.0 → 1.1.1

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: ec157eccf748c923a3f44138390f064e4b3aea347fdfe9744be6a5fa9954a947
4
- data.tar.gz: f6a433a5a7c3dc60806045240bd71ee4817fc8c1cf36a0af37fc66098821ff36
3
+ metadata.gz: e0ea3c8187e852192d22a16567b163eb0247b233d60503bee24527acbdc3a2cd
4
+ data.tar.gz: 73925718cdda63a38c982df326c6e34245f72a1bf7960415921ffb2105de6b66
5
5
  SHA512:
6
- metadata.gz: 8da50a2d1a78c22b997ab57c94476ee53abffb30688c4222982543dd84e9ed9dc97a99fd9a128a6fb4ba307f83d545e239291354ef67df0f66cfc7f4424b6d4c
7
- data.tar.gz: 0fc67b6d496d3472a1f69ea3105d51da358d1ae3f48f1715bbcc24e02ffd229ff144319f493ecec23937f6b161ef00f11eaecba06e0b12fc49e480140bb9e1e8
6
+ metadata.gz: d420a8c6d38af18a3928713eccd59403703cee04c7692a8c042eb381866af371b830501cecdca8a40e21797f620ae24d83428d3c86bd3b32954319b8c85fc9c3
7
+ data.tar.gz: 361fc238a0c34c0721f0ee12f54e1aa8a5a0d95aca361cbdb06e9e21220c1c15c36058b80c0c2a6c5e16aa76c2402d31eae6ce6a5a223a7f3747af2241b8e9ea
data/README.md CHANGED
@@ -41,11 +41,12 @@ Main differences between rbs_activerecord and rbs_rails are:
41
41
  * Support `alias_attribute` ([#263](https://github.com/pocke/rbs_rails/pull/263))
42
42
  * Support generating model definitions within the concern module ([#209](https://github.com/pocke/rbs_rails/pull/209))
43
43
  * Support extension ActiveRecord from 3rd party gems ([#254](https://github.com/pocke/rbs_rails/pull/254))
44
- * ex. kaminari
44
+ * ex. [kaminari-activerecord](https://github.com/ruby/gem_rbs_collection/pull/725)
45
45
  * Support composite primary keys ([#275](https://github.com/pocke/rbs_rails/pull/275))
46
46
  * Extend return types of #pluck ([#273](https://github.com/pocke/rbs_rails/pull/273))
47
47
  * Override types of CollectionProxy ([#289](https://github.com/pocke/rbs_rails/pull/289))
48
48
  * Bug fixes
49
+ * [#290](https://github.com/pocke/rbs_rails/pull/290)
49
50
  * [#286](https://github.com/pocke/rbs_rails/pull/286)
50
51
  * [#285](https://github.com/pocke/rbs_rails/pull/285)
51
52
  * [#278](https://github.com/pocke/rbs_rails/pull/278)
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RbsActiverecord
4
+ class Generator
5
+ module Enum
6
+ class Mappings < Base
7
+ attr_reader :model #: RbsActiverecord::Model
8
+ attr_reader :declarations #: Array[Prism::CallNode]
9
+
10
+ # @rbs model: RbsActiverecord::Model
11
+ # @rbs declarations: Hash[String, Array[Prism::CallNode]]
12
+ def initialize(model, declarations) #: void
13
+ @model = model
14
+ @declarations = declarations.fetch(model.klass.name.to_s, [])
15
+
16
+ super()
17
+ end
18
+
19
+ def generate #: String
20
+ <<~RBS.strip
21
+ module GeneratedEnumMappingMethods
22
+ #{enums.map { |node| enum(node) }.join("\n")}
23
+ end
24
+ RBS
25
+ end
26
+
27
+ private
28
+
29
+ def enums #: Array[Prism::CallNode]
30
+ declarations.select { |node| node.name == :enum }
31
+ end
32
+
33
+ # @rbs node: Prism::CallNode
34
+ def enum(node) #: String
35
+ name, = parse_arguments(node)
36
+
37
+ return "" unless name
38
+
39
+ "def #{name.to_s.pluralize}: () -> ActiveSupport::HashWithIndifferentAccess[Symbol, untyped]"
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -31,6 +31,7 @@ module RbsActiverecord
31
31
  #{DelegatedType::InstanceMethods.new(model, declarations).generate}
32
32
  #{DelegatedType::Scopes.new(model, declarations).generate}
33
33
  #{Enum::InstanceMethods.new(model, declarations).generate}
34
+ #{Enum::Mappings.new(model, declarations).generate}
34
35
  #{Enum::Scopes.new(model, declarations).generate}
35
36
  #{Scopes.new(model, declarations).generate}
36
37
 
@@ -66,6 +67,7 @@ module RbsActiverecord
66
67
 
67
68
  extend ::ActiveRecord::Base::ClassMethods[#{klass_name}, #{klass_name}::ActiveRecord_Relation, #{primary_key_type}]
68
69
  #{scope_class_methods}
70
+ extend GeneratedEnumMappingMethods
69
71
  extend GeneratedPluckOverloads
70
72
 
71
73
  include GeneratedActiveStorageInstanceMethods
@@ -3,8 +3,6 @@
3
3
  module RbsActiverecord
4
4
  module Parser
5
5
  module Evaluator
6
- # @rbs! def self.eval_node: (Prism::Node node) -> untyped
7
-
8
6
  # @rbs node: Prism::Node
9
7
  def eval_node(node) #: untyped # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
10
8
  case node
@@ -4,14 +4,6 @@ require "prism"
4
4
 
5
5
  module RbsActiverecord
6
6
  module Parser
7
- # NOTE: rbs-inline-0.9.0 does not support module_function yet.
8
- # refs: https://github.com/soutaro/rbs-inline/pull/118
9
- #
10
- # @rbs!
11
- # def self.parse: (String code) -> Hash[String, Array[Prism::CallNode]]
12
- # def self.parse_file: (String filename) -> Hash[String, Array[Prism::CallNode]]
13
- # def self.eval_node: (Prism::Node node) -> untyped
14
-
15
7
  # @rbs code: String
16
8
  def parse(code) #: Hash[String, Array[Prism::CallNode]]
17
9
  result = Prism.parse(code)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RbsActiverecord
4
- VERSION = "1.1.0"
4
+ VERSION = "1.1.1"
5
5
  end
@@ -11,6 +11,7 @@ require_relative "rbs_activerecord/generator/delegated_type/instance_methods"
11
11
  require_relative "rbs_activerecord/generator/delegated_type/scopes"
12
12
  require_relative "rbs_activerecord/generator/enum/base"
13
13
  require_relative "rbs_activerecord/generator/enum/instance_methods"
14
+ require_relative "rbs_activerecord/generator/enum/mappings"
14
15
  require_relative "rbs_activerecord/generator/enum/scopes"
15
16
  require_relative "rbs_activerecord/generator/pluck_overloads"
16
17
  require_relative "rbs_activerecord/generator/scopes"
@@ -6,7 +6,7 @@ gems:
6
6
  source:
7
7
  type: git
8
8
  name: ruby/gem_rbs_collection
9
- revision: 9b07b7bde4c9f656f3f6d785bd676320032cecb4
9
+ revision: 5fcf7d45b7c430a651c5996280d9991c781fcf14
10
10
  remote: https://github.com/ruby/gem_rbs_collection.git
11
11
  repo_dir: gems
12
12
  - name: actionview
@@ -14,7 +14,7 @@ gems:
14
14
  source:
15
15
  type: git
16
16
  name: ruby/gem_rbs_collection
17
- revision: 9b07b7bde4c9f656f3f6d785bd676320032cecb4
17
+ revision: 5fcf7d45b7c430a651c5996280d9991c781fcf14
18
18
  remote: https://github.com/ruby/gem_rbs_collection.git
19
19
  repo_dir: gems
20
20
  - name: activejob
@@ -22,7 +22,7 @@ gems:
22
22
  source:
23
23
  type: git
24
24
  name: ruby/gem_rbs_collection
25
- revision: 9b07b7bde4c9f656f3f6d785bd676320032cecb4
25
+ revision: 5fcf7d45b7c430a651c5996280d9991c781fcf14
26
26
  remote: https://github.com/ruby/gem_rbs_collection.git
27
27
  repo_dir: gems
28
28
  - name: activemodel
@@ -30,7 +30,7 @@ gems:
30
30
  source:
31
31
  type: git
32
32
  name: ruby/gem_rbs_collection
33
- revision: 9b07b7bde4c9f656f3f6d785bd676320032cecb4
33
+ revision: 5fcf7d45b7c430a651c5996280d9991c781fcf14
34
34
  remote: https://github.com/ruby/gem_rbs_collection.git
35
35
  repo_dir: gems
36
36
  - name: activerecord
@@ -38,7 +38,7 @@ gems:
38
38
  source:
39
39
  type: git
40
40
  name: ruby/gem_rbs_collection
41
- revision: 9b07b7bde4c9f656f3f6d785bd676320032cecb4
41
+ revision: 5fcf7d45b7c430a651c5996280d9991c781fcf14
42
42
  remote: https://github.com/ruby/gem_rbs_collection.git
43
43
  repo_dir: gems
44
44
  - name: activestorage
@@ -46,7 +46,7 @@ gems:
46
46
  source:
47
47
  type: git
48
48
  name: ruby/gem_rbs_collection
49
- revision: 9b07b7bde4c9f656f3f6d785bd676320032cecb4
49
+ revision: 5fcf7d45b7c430a651c5996280d9991c781fcf14
50
50
  remote: https://github.com/ruby/gem_rbs_collection.git
51
51
  repo_dir: gems
52
52
  - name: activesupport
@@ -54,7 +54,7 @@ gems:
54
54
  source:
55
55
  type: git
56
56
  name: ruby/gem_rbs_collection
57
- revision: 9b07b7bde4c9f656f3f6d785bd676320032cecb4
57
+ revision: 5fcf7d45b7c430a651c5996280d9991c781fcf14
58
58
  remote: https://github.com/ruby/gem_rbs_collection.git
59
59
  repo_dir: gems
60
60
  - name: ast
@@ -62,7 +62,7 @@ gems:
62
62
  source:
63
63
  type: git
64
64
  name: ruby/gem_rbs_collection
65
- revision: 9b07b7bde4c9f656f3f6d785bd676320032cecb4
65
+ revision: 5fcf7d45b7c430a651c5996280d9991c781fcf14
66
66
  remote: https://github.com/ruby/gem_rbs_collection.git
67
67
  repo_dir: gems
68
68
  - name: base64
@@ -74,7 +74,7 @@ gems:
74
74
  source:
75
75
  type: git
76
76
  name: ruby/gem_rbs_collection
77
- revision: 9b07b7bde4c9f656f3f6d785bd676320032cecb4
77
+ revision: 5fcf7d45b7c430a651c5996280d9991c781fcf14
78
78
  remote: https://github.com/ruby/gem_rbs_collection.git
79
79
  repo_dir: gems
80
80
  - name: benchmark
@@ -94,7 +94,7 @@ gems:
94
94
  source:
95
95
  type: git
96
96
  name: ruby/gem_rbs_collection
97
- revision: 9b07b7bde4c9f656f3f6d785bd676320032cecb4
97
+ revision: 5fcf7d45b7c430a651c5996280d9991c781fcf14
98
98
  remote: https://github.com/ruby/gem_rbs_collection.git
99
99
  repo_dir: gems
100
100
  - name: connection_pool
@@ -102,7 +102,7 @@ gems:
102
102
  source:
103
103
  type: git
104
104
  name: ruby/gem_rbs_collection
105
- revision: 9b07b7bde4c9f656f3f6d785bd676320032cecb4
105
+ revision: 5fcf7d45b7c430a651c5996280d9991c781fcf14
106
106
  remote: https://github.com/ruby/gem_rbs_collection.git
107
107
  repo_dir: gems
108
108
  - name: date
@@ -130,7 +130,7 @@ gems:
130
130
  source:
131
131
  type: git
132
132
  name: ruby/gem_rbs_collection
133
- revision: 9b07b7bde4c9f656f3f6d785bd676320032cecb4
133
+ revision: 5fcf7d45b7c430a651c5996280d9991c781fcf14
134
134
  remote: https://github.com/ruby/gem_rbs_collection.git
135
135
  repo_dir: gems
136
136
  - name: i18n
@@ -138,7 +138,7 @@ gems:
138
138
  source:
139
139
  type: git
140
140
  name: ruby/gem_rbs_collection
141
- revision: 9b07b7bde4c9f656f3f6d785bd676320032cecb4
141
+ revision: 5fcf7d45b7c430a651c5996280d9991c781fcf14
142
142
  remote: https://github.com/ruby/gem_rbs_collection.git
143
143
  repo_dir: gems
144
144
  - name: io-console
@@ -158,7 +158,7 @@ gems:
158
158
  source:
159
159
  type: git
160
160
  name: ruby/gem_rbs_collection
161
- revision: 9b07b7bde4c9f656f3f6d785bd676320032cecb4
161
+ revision: 5fcf7d45b7c430a651c5996280d9991c781fcf14
162
162
  remote: https://github.com/ruby/gem_rbs_collection.git
163
163
  repo_dir: gems
164
164
  - name: minitest
@@ -178,7 +178,7 @@ gems:
178
178
  source:
179
179
  type: git
180
180
  name: ruby/gem_rbs_collection
181
- revision: 9b07b7bde4c9f656f3f6d785bd676320032cecb4
181
+ revision: 5fcf7d45b7c430a651c5996280d9991c781fcf14
182
182
  remote: https://github.com/ruby/gem_rbs_collection.git
183
183
  repo_dir: gems
184
184
  - name: openssl
@@ -194,7 +194,7 @@ gems:
194
194
  source:
195
195
  type: git
196
196
  name: ruby/gem_rbs_collection
197
- revision: 9b07b7bde4c9f656f3f6d785bd676320032cecb4
197
+ revision: 5fcf7d45b7c430a651c5996280d9991c781fcf14
198
198
  remote: https://github.com/ruby/gem_rbs_collection.git
199
199
  repo_dir: gems
200
200
  - name: parser
@@ -202,7 +202,7 @@ gems:
202
202
  source:
203
203
  type: git
204
204
  name: ruby/gem_rbs_collection
205
- revision: 9b07b7bde4c9f656f3f6d785bd676320032cecb4
205
+ revision: 5fcf7d45b7c430a651c5996280d9991c781fcf14
206
206
  remote: https://github.com/ruby/gem_rbs_collection.git
207
207
  repo_dir: gems
208
208
  - name: pathname
@@ -218,7 +218,7 @@ gems:
218
218
  source:
219
219
  type: git
220
220
  name: ruby/gem_rbs_collection
221
- revision: 9b07b7bde4c9f656f3f6d785bd676320032cecb4
221
+ revision: 5fcf7d45b7c430a651c5996280d9991c781fcf14
222
222
  remote: https://github.com/ruby/gem_rbs_collection.git
223
223
  repo_dir: gems
224
224
  - name: rails-dom-testing
@@ -226,7 +226,7 @@ gems:
226
226
  source:
227
227
  type: git
228
228
  name: ruby/gem_rbs_collection
229
- revision: 9b07b7bde4c9f656f3f6d785bd676320032cecb4
229
+ revision: 5fcf7d45b7c430a651c5996280d9991c781fcf14
230
230
  remote: https://github.com/ruby/gem_rbs_collection.git
231
231
  repo_dir: gems
232
232
  - name: rails-html-sanitizer
@@ -234,7 +234,7 @@ gems:
234
234
  source:
235
235
  type: git
236
236
  name: ruby/gem_rbs_collection
237
- revision: 9b07b7bde4c9f656f3f6d785bd676320032cecb4
237
+ revision: 5fcf7d45b7c430a651c5996280d9991c781fcf14
238
238
  remote: https://github.com/ruby/gem_rbs_collection.git
239
239
  repo_dir: gems
240
240
  - name: railties
@@ -242,7 +242,7 @@ gems:
242
242
  source:
243
243
  type: git
244
244
  name: ruby/gem_rbs_collection
245
- revision: 9b07b7bde4c9f656f3f6d785bd676320032cecb4
245
+ revision: 5fcf7d45b7c430a651c5996280d9991c781fcf14
246
246
  remote: https://github.com/ruby/gem_rbs_collection.git
247
247
  repo_dir: gems
248
248
  - name: rainbow
@@ -250,7 +250,7 @@ gems:
250
250
  source:
251
251
  type: git
252
252
  name: ruby/gem_rbs_collection
253
- revision: 9b07b7bde4c9f656f3f6d785bd676320032cecb4
253
+ revision: 5fcf7d45b7c430a651c5996280d9991c781fcf14
254
254
  remote: https://github.com/ruby/gem_rbs_collection.git
255
255
  repo_dir: gems
256
256
  - name: rake
@@ -258,7 +258,7 @@ gems:
258
258
  source:
259
259
  type: git
260
260
  name: ruby/gem_rbs_collection
261
- revision: 9b07b7bde4c9f656f3f6d785bd676320032cecb4
261
+ revision: 5fcf7d45b7c430a651c5996280d9991c781fcf14
262
262
  remote: https://github.com/ruby/gem_rbs_collection.git
263
263
  repo_dir: gems
264
264
  - name: rbs
@@ -274,7 +274,7 @@ gems:
274
274
  source:
275
275
  type: git
276
276
  name: ruby/gem_rbs_collection
277
- revision: 9b07b7bde4c9f656f3f6d785bd676320032cecb4
277
+ revision: 5fcf7d45b7c430a651c5996280d9991c781fcf14
278
278
  remote: https://github.com/ruby/gem_rbs_collection.git
279
279
  repo_dir: gems
280
280
  - name: rubocop
@@ -282,7 +282,7 @@ gems:
282
282
  source:
283
283
  type: git
284
284
  name: ruby/gem_rbs_collection
285
- revision: 9b07b7bde4c9f656f3f6d785bd676320032cecb4
285
+ revision: 5fcf7d45b7c430a651c5996280d9991c781fcf14
286
286
  remote: https://github.com/ruby/gem_rbs_collection.git
287
287
  repo_dir: gems
288
288
  - name: rubocop-ast
@@ -290,7 +290,7 @@ gems:
290
290
  source:
291
291
  type: git
292
292
  name: ruby/gem_rbs_collection
293
- revision: 9b07b7bde4c9f656f3f6d785bd676320032cecb4
293
+ revision: 5fcf7d45b7c430a651c5996280d9991c781fcf14
294
294
  remote: https://github.com/ruby/gem_rbs_collection.git
295
295
  repo_dir: gems
296
296
  - name: securerandom
@@ -310,7 +310,7 @@ gems:
310
310
  source:
311
311
  type: git
312
312
  name: ruby/gem_rbs_collection
313
- revision: 9b07b7bde4c9f656f3f6d785bd676320032cecb4
313
+ revision: 5fcf7d45b7c430a651c5996280d9991c781fcf14
314
314
  remote: https://github.com/ruby/gem_rbs_collection.git
315
315
  repo_dir: gems
316
316
  - name: tempfile
@@ -322,7 +322,7 @@ gems:
322
322
  source:
323
323
  type: git
324
324
  name: ruby/gem_rbs_collection
325
- revision: 9b07b7bde4c9f656f3f6d785bd676320032cecb4
325
+ revision: 5fcf7d45b7c430a651c5996280d9991c781fcf14
326
326
  remote: https://github.com/ruby/gem_rbs_collection.git
327
327
  repo_dir: gems
328
328
  - name: time
@@ -342,7 +342,7 @@ gems:
342
342
  source:
343
343
  type: git
344
344
  name: ruby/gem_rbs_collection
345
- revision: 9b07b7bde4c9f656f3f6d785bd676320032cecb4
345
+ revision: 5fcf7d45b7c430a651c5996280d9991c781fcf14
346
346
  remote: https://github.com/ruby/gem_rbs_collection.git
347
347
  repo_dir: gems
348
348
  - name: uri
@@ -0,0 +1,26 @@
1
+ # Generated from lib/rbs_activerecord/generator/enum/mappings.rb with RBS::Inline
2
+
3
+ module RbsActiverecord
4
+ class Generator
5
+ module Enum
6
+ class Mappings < Base
7
+ attr_reader model: RbsActiverecord::Model
8
+
9
+ attr_reader declarations: Array[Prism::CallNode]
10
+
11
+ # @rbs model: RbsActiverecord::Model
12
+ # @rbs declarations: Hash[String, Array[Prism::CallNode]]
13
+ def initialize: (RbsActiverecord::Model model, Hash[String, Array[Prism::CallNode]] declarations) -> void
14
+
15
+ def generate: () -> String
16
+
17
+ private
18
+
19
+ def enums: () -> Array[Prism::CallNode]
20
+
21
+ # @rbs node: Prism::CallNode
22
+ def enum: (Prism::CallNode node) -> String
23
+ end
24
+ end
25
+ end
26
+ end
@@ -3,10 +3,8 @@
3
3
  module RbsActiverecord
4
4
  module Parser
5
5
  module Evaluator
6
- def self.eval_node: (Prism::Node node) -> untyped
7
-
8
6
  # @rbs node: Prism::Node
9
- def eval_node: (Prism::Node node) -> untyped
7
+ def self?.eval_node: (Prism::Node node) -> untyped
10
8
  end
11
9
  end
12
10
  end
@@ -2,18 +2,12 @@
2
2
 
3
3
  module RbsActiverecord
4
4
  module Parser
5
- def self.parse: (String code) -> Hash[String, Array[Prism::CallNode]]
6
-
7
- def self.parse_file: (String filename) -> Hash[String, Array[Prism::CallNode]]
8
-
9
- def self.eval_node: (Prism::Node node) -> untyped
10
-
11
5
  # @rbs code: String
12
- def parse: (String code) -> Hash[String, Array[Prism::CallNode]]
6
+ def self?.parse: (String code) -> Hash[String, Array[Prism::CallNode]]
13
7
 
14
- def parse_file: (untyped filename) -> Hash[String, Array[Prism::CallNode]]
8
+ def self?.parse_file: (untyped filename) -> Hash[String, Array[Prism::CallNode]]
15
9
 
16
10
  # @rbs node: Prism::Node
17
- def eval_node: (Prism::Node node) -> untyped
11
+ def self?.eval_node: (Prism::Node node) -> untyped
18
12
  end
19
13
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rbs_activerecord
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Takeshi KOMIYA
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-11-16 00:00:00.000000000 Z
11
+ date: 2024-11-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -78,6 +78,7 @@ files:
78
78
  - lib/rbs_activerecord/generator/delegated_type/scopes.rb
79
79
  - lib/rbs_activerecord/generator/enum/base.rb
80
80
  - lib/rbs_activerecord/generator/enum/instance_methods.rb
81
+ - lib/rbs_activerecord/generator/enum/mappings.rb
81
82
  - lib/rbs_activerecord/generator/enum/scopes.rb
82
83
  - lib/rbs_activerecord/generator/pluck_overloads.rb
83
84
  - lib/rbs_activerecord/generator/scopes.rb
@@ -104,6 +105,7 @@ files:
104
105
  - sig/rbs_activerecord/generator/delegated_type/scopes.rbs
105
106
  - sig/rbs_activerecord/generator/enum/base.rbs
106
107
  - sig/rbs_activerecord/generator/enum/instance_methods.rbs
108
+ - sig/rbs_activerecord/generator/enum/mappings.rbs
107
109
  - sig/rbs_activerecord/generator/enum/scopes.rbs
108
110
  - sig/rbs_activerecord/generator/pluck_overloads.rbs
109
111
  - sig/rbs_activerecord/generator/scopes.rbs