store_attribute 1.1.1 → 1.2.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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 601846a5ef07068e0777b17cfb7896a6bcd1fe32ef93ac107f957c568a6598de
|
4
|
+
data.tar.gz: 7ebee7679babde4188b07aa0504310001edbe31758070112b6f5c0e48eadc83d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 64d0e3b562bd62b6e8b65b993f049b3af805d0a38f075218eaa05993f7229befbf10f21e59dd1709ddd1faa5397e20ca4f02c8800a703cee7f3db79b12a28a98
|
7
|
+
data.tar.gz: 29623e721a38b1bf646f3a45c00c605c4162236716624e3cb8a0dceee69641d254145baa84b58008e3fe61084b1eb76249a34775f186bbe86861eca827ba2856
|
data/CHANGELOG.md
CHANGED
@@ -157,16 +157,13 @@ module ActiveRecord
|
|
157
157
|
|
158
158
|
def _define_store_attribute(store_name)
|
159
159
|
attr_name = store_name.to_s
|
160
|
-
was_type = attributes_to_define_after_schema_loads[attr_name]&.first
|
161
|
-
|
162
|
-
# For Rails <6.1
|
163
|
-
use_decorator = respond_to?(:decorate_attribute_type) && method(:decorate_attribute_type).parameters.count { |type, _| type == :req } == 2
|
164
160
|
|
165
161
|
defaultik = Type::TypedStore::Defaultik.new
|
166
162
|
|
167
163
|
owner = self
|
168
164
|
|
169
|
-
|
165
|
+
# For Rails <6.1
|
166
|
+
if respond_to?(:decorate_attribute_type) && method(:decorate_attribute_type).parameters.count { |type, _| type == :req } == 2
|
170
167
|
decorate_attribute_type(attr_name, "typed_accessor_for_#{attr_name}") do |subtype|
|
171
168
|
subtypes = _local_typed_stored_attributes[attr_name]
|
172
169
|
type = Type::TypedStore.create_from_type(subtype)
|
@@ -180,7 +177,25 @@ module ActiveRecord
|
|
180
177
|
|
181
178
|
type
|
182
179
|
end
|
180
|
+
# Rails >7.1
|
181
|
+
elsif respond_to?(:decorate_attributes)
|
182
|
+
decorate_attributes([attr_name]) do |_, subtype|
|
183
|
+
subtypes = _local_typed_stored_attributes[attr_name]
|
184
|
+
type = Type::TypedStore.create_from_type(subtype)
|
185
|
+
type.owner = owner
|
186
|
+
defaultik.type = type
|
187
|
+
subtypes.each do |name, (cast_type, options)|
|
188
|
+
type.add_typed_key(name, cast_type, **options.symbolize_keys)
|
189
|
+
end
|
190
|
+
|
191
|
+
type
|
192
|
+
end
|
193
|
+
|
194
|
+
attribute(attr_name, default: defaultik.proc)
|
195
|
+
# Rails >=6.1, <=7.1
|
183
196
|
else
|
197
|
+
was_type = attributes_to_define_after_schema_loads[attr_name]&.first
|
198
|
+
|
184
199
|
attribute(attr_name, default: defaultik.proc) do |subtype|
|
185
200
|
subtypes = _local_typed_stored_attributes[attr_name]
|
186
201
|
subtype = _lookup_cast_type(attr_name, was_type, {}) if defined?(_lookup_cast_type)
|
@@ -30,7 +30,7 @@ module ActiveRecord
|
|
30
30
|
def initialize(subtype)
|
31
31
|
@accessor_types = {}
|
32
32
|
@defaults = {}
|
33
|
-
@
|
33
|
+
@subtype = subtype
|
34
34
|
super(subtype)
|
35
35
|
end
|
36
36
|
|
@@ -118,7 +118,7 @@ module ActiveRecord
|
|
118
118
|
def key_to_cast(val, key)
|
119
119
|
return key if val.key?(key)
|
120
120
|
return key.to_sym if val.key?(key.to_sym)
|
121
|
-
|
121
|
+
key if defaults.key?(key)
|
122
122
|
end
|
123
123
|
|
124
124
|
def typed?(key)
|
@@ -133,7 +133,11 @@ module ActiveRecord
|
|
133
133
|
owner&.store_attribute_unset_values_fallback_to_default && defaults.key?(key)
|
134
134
|
end
|
135
135
|
|
136
|
-
|
136
|
+
def store_accessor
|
137
|
+
subtype.accessor
|
138
|
+
end
|
139
|
+
|
140
|
+
attr_reader :accessor_types, :defaults, :subtype, :owner
|
137
141
|
end
|
138
142
|
end
|
139
143
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: store_attribute
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- palkan
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-11-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -106,7 +106,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
106
106
|
- !ruby/object:Gem::Version
|
107
107
|
version: '0'
|
108
108
|
requirements: []
|
109
|
-
rubygems_version: 3.4.
|
109
|
+
rubygems_version: 3.4.20
|
110
110
|
signing_key:
|
111
111
|
specification_version: 4
|
112
112
|
summary: ActiveRecord extension which adds typecasting to store accessors
|