rbs_active_hash 0.1.0 → 1.0.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: 233acb3a91cc07f0b2db21995c7906c43269c801fab32a1bd3192729e0d67bbd
4
- data.tar.gz: 276ea886963014e06eff21094fa210953656c014b01fb07b0690f777934c0523
3
+ metadata.gz: a40c37520928e6b4e5f6049311691c16966c1819008648702b9fdfa7abb0a156
4
+ data.tar.gz: c2d4212d760b5970ae09919641a88cdca6bd4469e12271a545d7226692281b99
5
5
  SHA512:
6
- metadata.gz: ef51ed27e545012fe365856d645f554999b0eb5805936b57a3b478f4d67ef95d8084a66a07433d8283f51df7a0cb8337180fc9a4d19a2e3db3655d084f9270eb
7
- data.tar.gz: 1f47c140e0b92b40abc9d534a9f45c5a387d100e59316514c269764d04936185a3f9566a1539a7833c202e0e1bf21ee8e1fedb7b3330ab806fe55a9e942394d8
6
+ metadata.gz: cf19e092d7dac5139dd6ba69bc136e692efc0b4dd6624f084e24de9a57327ec32bb4dcd777c7da6b25586925c4103738bf2796f962db200f5077ad7356f9ff59
7
+ data.tar.gz: c9a1fc5bcf3c671f2cc4954b0639ea13a461318583d55434e3bbe58f7036594b215d587b59eddedb89f5db6702cb5451c64ec0f45bcaa0cb262bf2b8b79e8941
data/.rubocop.yml CHANGED
@@ -18,3 +18,9 @@ Layout/LineLength:
18
18
  Metrics/BlockLength:
19
19
  Exclude:
20
20
  - spec/**/*_spec.rb
21
+
22
+ Metrics/MethodLength:
23
+ Max: 20
24
+
25
+ Metrics/PerceivedComplexity:
26
+ Max: 10
data/Gemfile CHANGED
@@ -15,3 +15,9 @@ group :development do
15
15
 
16
16
  gem "steep"
17
17
  end
18
+
19
+ # dependencies only for signature
20
+ group :signature do
21
+ gem "activerecord"
22
+ gem "railties"
23
+ end
data/Gemfile.lock CHANGED
@@ -1,25 +1,46 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rbs_active_hash (0.1.0)
4
+ rbs_active_hash (1.0.0)
5
5
  active_hash
6
6
  rbs_rails
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
+ actionpack (7.0.5)
12
+ actionview (= 7.0.5)
13
+ activesupport (= 7.0.5)
14
+ rack (~> 2.0, >= 2.2.4)
15
+ rack-test (>= 0.6.3)
16
+ rails-dom-testing (~> 2.0)
17
+ rails-html-sanitizer (~> 1.0, >= 1.2.0)
18
+ actionview (7.0.5)
19
+ activesupport (= 7.0.5)
20
+ builder (~> 3.1)
21
+ erubi (~> 1.4)
22
+ rails-dom-testing (~> 2.0)
23
+ rails-html-sanitizer (~> 1.1, >= 1.2.0)
11
24
  active_hash (3.2.0)
12
25
  activesupport (>= 5.0.0)
26
+ activemodel (7.0.5)
27
+ activesupport (= 7.0.5)
28
+ activerecord (7.0.5)
29
+ activemodel (= 7.0.5)
30
+ activesupport (= 7.0.5)
13
31
  activesupport (7.0.5)
14
32
  concurrent-ruby (~> 1.0, >= 1.0.2)
15
33
  i18n (>= 1.6, < 2)
16
34
  minitest (>= 5.1)
17
35
  tzinfo (~> 2.0)
18
36
  ast (2.4.2)
37
+ builder (3.2.4)
19
38
  coderay (1.1.3)
20
39
  concurrent-ruby (1.2.2)
40
+ crass (1.0.6)
21
41
  csv (3.2.6)
22
42
  diff-lcs (1.5.0)
43
+ erubi (1.12.0)
23
44
  ffi (1.15.5)
24
45
  fileutils (1.7.1)
25
46
  i18n (1.14.0)
@@ -30,14 +51,38 @@ GEM
30
51
  rb-fsevent (~> 0.10, >= 0.10.3)
31
52
  rb-inotify (~> 0.9, >= 0.9.10)
32
53
  logger (1.5.3)
54
+ loofah (2.21.3)
55
+ crass (~> 1.0.2)
56
+ nokogiri (>= 1.12.0)
33
57
  method_source (1.0.0)
34
58
  minitest (5.18.0)
59
+ nokogiri (1.15.2-x86_64-darwin)
60
+ racc (~> 1.4)
61
+ nokogiri (1.15.2-x86_64-linux)
62
+ racc (~> 1.4)
35
63
  parallel (1.23.0)
36
64
  parser (3.2.2.1)
37
65
  ast (~> 2.4.1)
38
66
  pry (0.14.2)
39
67
  coderay (~> 1.1)
40
68
  method_source (~> 1.0)
69
+ racc (1.7.0)
70
+ rack (2.2.7)
71
+ rack-test (2.1.0)
72
+ rack (>= 1.3)
73
+ rails-dom-testing (2.0.3)
74
+ activesupport (>= 4.2.0)
75
+ nokogiri (>= 1.6)
76
+ rails-html-sanitizer (1.6.0)
77
+ loofah (~> 2.21)
78
+ nokogiri (~> 1.14)
79
+ railties (7.0.5)
80
+ actionpack (= 7.0.5)
81
+ activesupport (= 7.0.5)
82
+ method_source
83
+ rake (>= 12.2)
84
+ thor (~> 1.0)
85
+ zeitwerk (~> 2.5)
41
86
  rainbow (3.1.1)
42
87
  rake (13.0.6)
43
88
  rb-fsevent (0.11.2)
@@ -97,15 +142,19 @@ GEM
97
142
  strscan (3.0.6)
98
143
  terminal-table (3.0.2)
99
144
  unicode-display_width (>= 1.1.1, < 3)
145
+ thor (1.2.2)
100
146
  tzinfo (2.0.6)
101
147
  concurrent-ruby (~> 1.0)
102
148
  unicode-display_width (2.4.2)
149
+ zeitwerk (2.6.8)
103
150
 
104
151
  PLATFORMS
105
- x86_64-linux
106
152
  x86_64-darwin-21
153
+ x86_64-linux
107
154
 
108
155
  DEPENDENCIES
156
+ activerecord
157
+ railties
109
158
  rake (~> 13.0)
110
159
  rbs_active_hash!
111
160
  rspec
@@ -11,7 +11,7 @@ module RbsActiveHash
11
11
 
12
12
  RbsActiveHash::RakeTask.new
13
13
  rescue LoadError
14
- # failed to load rbs_rails. Skip to load rbs_rails tasks.
14
+ # failed to load rbs_active_hash. Skip to load rbs_active_hash tasks.
15
15
  end
16
16
  RUBY
17
17
  end
@@ -45,9 +45,8 @@ module RbsActiveHash
45
45
  def header
46
46
  module_defs = module_names.map { |module_name| "module #{module_name}" }
47
47
 
48
- superclass_name = RbsRails::Util.module_name(klass.superclass)
49
48
  class_name = klass.name.split("::").last
50
- class_def = "class #{class_name} < ::#{superclass_name}"
49
+ class_def = "class #{class_name} < ::#{klass.superclass}"
51
50
 
52
51
  (module_defs + [class_def]).join("\n")
53
52
  end
@@ -86,12 +85,13 @@ module RbsActiveHash
86
85
 
87
86
  def method_decls
88
87
  method_names.map do |method|
88
+ method_type = stringify_type(method_types.fetch(method, "untyped"))
89
89
  <<~RBS
90
- def #{method}: () -> untyped
91
- def #{method}=: (untyped value) -> void
90
+ def #{method}: () -> #{method_type}
91
+ def #{method}=: (#{method_type} value) -> void
92
92
  def #{method}?: () -> bool
93
- def self.find_by_#{method}: (untyped value) -> self?
94
- def self.find_all_by_#{method}: (untyped value) -> Array[self]
93
+ def self.find_by_#{method}: (#{method_type} value) -> self?
94
+ def self.find_all_by_#{method}: (#{method_type} value) -> Array[self]
95
95
  RBS
96
96
  end.join("\n")
97
97
  end
@@ -103,6 +103,16 @@ module RbsActiveHash
103
103
  method_names.uniq.select { |k| k != :id && valid_field_name?(k) }
104
104
  end
105
105
 
106
+ def method_types
107
+ method_types = Hash.new { |hash, key| hash[key] = [] }
108
+ (klass.data || []).each do |record|
109
+ record.symbolize_keys.each do |key, value|
110
+ method_types[key] << value.class
111
+ end
112
+ end
113
+ method_types.transform_values(&:uniq)
114
+ end
115
+
106
116
  def valid_field_name?(name)
107
117
  name.to_s =~ /^[a-zA-Z_][a-zA-Z0-9_]*$/
108
118
  end
@@ -111,6 +121,25 @@ module RbsActiveHash
111
121
  "end\n" * klass.module_parents.size
112
122
  end
113
123
 
124
+ def stringify_type(type)
125
+ if [TrueClass, FalseClass].include?(type)
126
+ "bool"
127
+ elsif type == NilClass
128
+ "nil"
129
+ elsif type.is_a? Class
130
+ type.name
131
+ elsif type.is_a? Array
132
+ types = type.map { |t| stringify_type(t) }.uniq.sort
133
+ if types.delete("nil")
134
+ "(#{types.join(" | ")})?"
135
+ else
136
+ "(#{types.join(" | ")})"
137
+ end
138
+ else
139
+ type.to_s
140
+ end
141
+ end
142
+
114
143
  attr_reader :klass
115
144
  end
116
145
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RbsActiveHash
4
- VERSION = "0.1.0"
4
+ VERSION = "1.0.0"
5
5
  end
@@ -2,7 +2,7 @@
2
2
  sources:
3
3
  - type: git
4
4
  name: ruby/gem_rbs_collection
5
- revision: 28208148c7e64a25e9b86b9723b4c3a2cef14e81
5
+ revision: 280d44d7671abfa909f2966fbef94bca5be082de
6
6
  remote: https://github.com/ruby/gem_rbs_collection.git
7
7
  repo_dir: gems
8
8
  path: ".gem_rbs_collection"
@@ -11,6 +11,46 @@ gems:
11
11
  version: '0'
12
12
  source:
13
13
  type: stdlib
14
+ - name: actionpack
15
+ version: '6.0'
16
+ source:
17
+ type: git
18
+ name: ruby/gem_rbs_collection
19
+ revision: 280d44d7671abfa909f2966fbef94bca5be082de
20
+ remote: https://github.com/ruby/gem_rbs_collection.git
21
+ repo_dir: gems
22
+ - name: actionview
23
+ version: '6.0'
24
+ source:
25
+ type: git
26
+ name: ruby/gem_rbs_collection
27
+ revision: 280d44d7671abfa909f2966fbef94bca5be082de
28
+ remote: https://github.com/ruby/gem_rbs_collection.git
29
+ repo_dir: gems
30
+ - name: active_hash
31
+ version: '3.2'
32
+ source:
33
+ type: git
34
+ name: ruby/gem_rbs_collection
35
+ revision: 280d44d7671abfa909f2966fbef94bca5be082de
36
+ remote: https://github.com/ruby/gem_rbs_collection.git
37
+ repo_dir: gems
38
+ - name: activemodel
39
+ version: '7.0'
40
+ source:
41
+ type: git
42
+ name: ruby/gem_rbs_collection
43
+ revision: 280d44d7671abfa909f2966fbef94bca5be082de
44
+ remote: https://github.com/ruby/gem_rbs_collection.git
45
+ repo_dir: gems
46
+ - name: activerecord
47
+ version: '7.0'
48
+ source:
49
+ type: git
50
+ name: ruby/gem_rbs_collection
51
+ revision: 280d44d7671abfa909f2966fbef94bca5be082de
52
+ remote: https://github.com/ruby/gem_rbs_collection.git
53
+ repo_dir: gems
14
54
  - name: activesupport
15
55
  version: '7.0'
16
56
  source:
@@ -27,6 +67,10 @@ gems:
27
67
  revision: 28208148c7e64a25e9b86b9723b4c3a2cef14e81
28
68
  remote: https://github.com/ruby/gem_rbs_collection.git
29
69
  repo_dir: gems
70
+ - name: cgi
71
+ version: '0'
72
+ source:
73
+ type: stdlib
30
74
  - name: concurrent-ruby
31
75
  version: '1.1'
32
76
  source:
@@ -67,6 +111,14 @@ gems:
67
111
  version: '0'
68
112
  source:
69
113
  type: stdlib
114
+ - name: nokogiri
115
+ version: '1.11'
116
+ source:
117
+ type: git
118
+ name: ruby/gem_rbs_collection
119
+ revision: 280d44d7671abfa909f2966fbef94bca5be082de
120
+ remote: https://github.com/ruby/gem_rbs_collection.git
121
+ repo_dir: gems
70
122
  - name: optparse
71
123
  version: '0'
72
124
  source:
@@ -83,6 +135,30 @@ gems:
83
135
  version: '0'
84
136
  source:
85
137
  type: stdlib
138
+ - name: rack
139
+ version: '2.2'
140
+ source:
141
+ type: git
142
+ name: ruby/gem_rbs_collection
143
+ revision: 280d44d7671abfa909f2966fbef94bca5be082de
144
+ remote: https://github.com/ruby/gem_rbs_collection.git
145
+ repo_dir: gems
146
+ - name: rails-dom-testing
147
+ version: '2.0'
148
+ source:
149
+ type: git
150
+ name: ruby/gem_rbs_collection
151
+ revision: 280d44d7671abfa909f2966fbef94bca5be082de
152
+ remote: https://github.com/ruby/gem_rbs_collection.git
153
+ repo_dir: gems
154
+ - name: railties
155
+ version: '6.0'
156
+ source:
157
+ type: git
158
+ name: ruby/gem_rbs_collection
159
+ revision: 280d44d7671abfa909f2966fbef94bca5be082de
160
+ remote: https://github.com/ruby/gem_rbs_collection.git
161
+ repo_dir: gems
86
162
  - name: rainbow
87
163
  version: '3.0'
88
164
  source:
@@ -95,6 +171,10 @@ gems:
95
171
  version: 3.1.0
96
172
  source:
97
173
  type: rubygems
174
+ - name: rbs_rails
175
+ version: 0.12.0
176
+ source:
177
+ type: rubygems
98
178
  - name: rdoc
99
179
  version: '0'
100
180
  source:
@@ -103,6 +183,10 @@ gems:
103
183
  version: '0'
104
184
  source:
105
185
  type: stdlib
186
+ - name: tempfile
187
+ version: '0'
188
+ source:
189
+ type: stdlib
106
190
  - name: time
107
191
  version: '0'
108
192
  source:
@@ -111,4 +195,8 @@ gems:
111
195
  version: '0'
112
196
  source:
113
197
  type: stdlib
198
+ - name: uri
199
+ version: '0'
200
+ source:
201
+ type: stdlib
114
202
  gemfile_lock_path: Gemfile.lock
data/rbs_collection.yaml CHANGED
@@ -19,5 +19,3 @@ gems:
19
19
  - name: rbs
20
20
  - name: steep
21
21
  ignore: true
22
- - name: rbs_rails
23
- ignore: true
@@ -16,10 +16,13 @@ module RbsActiveHash
16
16
  def enum_decls: () -> String?
17
17
  def constants: () -> Array[String]
18
18
  def method_decls: () -> String
19
- def method_names: () -> Array[String]
19
+ def method_names: () -> Array[Symbol]
20
+ def method_types: () -> Hash[Symbol, untyped]
20
21
  def valid_field_name?: (String) -> boolish
21
22
  def footer: () -> String
22
23
 
24
+ def stringify_type: (untyped type) -> String
25
+
23
26
  attr_reader klass: Class
24
27
  end
25
28
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rbs_active_hash
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Takeshi KOMIYA
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-06-04 00:00:00.000000000 Z
11
+ date: 2023-06-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: active_hash