rbs_active_hash 0.1.1 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +6 -0
- data/Gemfile.lock +1 -1
- data/lib/rbs_active_hash/active_hash.rb +34 -4
- data/lib/rbs_active_hash/version.rb +1 -1
- data/sig/rbs_active_hash/active_hash.rbs +4 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a40c37520928e6b4e5f6049311691c16966c1819008648702b9fdfa7abb0a156
|
4
|
+
data.tar.gz: c2d4212d760b5970ae09919641a88cdca6bd4469e12271a545d7226692281b99
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cf19e092d7dac5139dd6ba69bc136e692efc0b4dd6624f084e24de9a57327ec32bb4dcd777c7da6b25586925c4103738bf2796f962db200f5077ad7356f9ff59
|
7
|
+
data.tar.gz: c9a1fc5bcf3c671f2cc4954b0639ea13a461318583d55434e3bbe58f7036594b215d587b59eddedb89f5db6702cb5451c64ec0f45bcaa0cb262bf2b8b79e8941
|
data/.rubocop.yml
CHANGED
data/Gemfile.lock
CHANGED
@@ -85,12 +85,13 @@ module RbsActiveHash
|
|
85
85
|
|
86
86
|
def method_decls
|
87
87
|
method_names.map do |method|
|
88
|
+
method_type = stringify_type(method_types.fetch(method, "untyped"))
|
88
89
|
<<~RBS
|
89
|
-
def #{method}: () ->
|
90
|
-
def #{method}=: (
|
90
|
+
def #{method}: () -> #{method_type}
|
91
|
+
def #{method}=: (#{method_type} value) -> void
|
91
92
|
def #{method}?: () -> bool
|
92
|
-
def self.find_by_#{method}: (
|
93
|
-
def self.find_all_by_#{method}: (
|
93
|
+
def self.find_by_#{method}: (#{method_type} value) -> self?
|
94
|
+
def self.find_all_by_#{method}: (#{method_type} value) -> Array[self]
|
94
95
|
RBS
|
95
96
|
end.join("\n")
|
96
97
|
end
|
@@ -102,6 +103,16 @@ module RbsActiveHash
|
|
102
103
|
method_names.uniq.select { |k| k != :id && valid_field_name?(k) }
|
103
104
|
end
|
104
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
|
+
|
105
116
|
def valid_field_name?(name)
|
106
117
|
name.to_s =~ /^[a-zA-Z_][a-zA-Z0-9_]*$/
|
107
118
|
end
|
@@ -110,6 +121,25 @@ module RbsActiveHash
|
|
110
121
|
"end\n" * klass.module_parents.size
|
111
122
|
end
|
112
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
|
+
|
113
143
|
attr_reader :klass
|
114
144
|
end
|
115
145
|
end
|
@@ -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[
|
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.
|
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-
|
11
|
+
date: 2023-06-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: active_hash
|