store_attribute 1.1.0 → 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2134f240621f2f546e5521fe4db4b66e3b6ec0a4a76ebb832fbcae8654c0904e
4
- data.tar.gz: 862ce5201d0c1ad548035161b0f51b50a9a540a85ae8be0a9c550976f918701c
3
+ metadata.gz: 6078ba7214bee86726edd35c8cfbac054907c2aada0e5644d63b906b1884cb37
4
+ data.tar.gz: b3ac4c23dfdc1f8412fccf67fe8c7e9a441943ae7d3adba95eb735e7cd5e0302
5
5
  SHA512:
6
- metadata.gz: efe4992702c419f392f4fcbfd16c0ab32c862acf4679e841a7a8c28d40e0fb2eb66c2b72b2ac0156517a49bce4ee7308ec75ffa64604d4b879c735da0201d7f3
7
- data.tar.gz: a9b8d3683abcd37f99a7c0ef68431e80e32a79537c5dab426e150a85b7d15c4b8ce1cb92e0a6c1c24031418286223e854fb2e2c73083c801781553f6559cd2c1
6
+ metadata.gz: 2c8b70decca97c29ec6b112265d318f7fcb598a87dccbcc6531fc7f9e1de8701830f7d963f6890cfb453704ad19b14e2b6550d9d513c33fbfadf85952a9491a4
7
+ data.tar.gz: 41a9e77501f4c9e4df33a06fa343c0377e8cb982b0dfda250003345e16d4afc635b39b99c9570ded1f7af27a6781b76c8dba013b3586bf699c048260159bf507
data/CHANGELOG.md CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
  ## master
4
4
 
5
+ ## 1.1.1 (2023-06-27)
6
+
7
+ - Lookup store attribute types only after schema load.
8
+
5
9
  ## 1.1.0 (2023-03-08) 🌷
6
10
 
7
11
  - Add configuration option to return default values when attribute key is not present in the serialized value ([@markedmondson][], [@palkan][]).
@@ -124,7 +124,7 @@ module ActiveRecord
124
124
  _define_predicate_method(name, prefix: prefix, suffix: suffix) if type == :boolean
125
125
 
126
126
  _define_store_attribute(store_name) if !_local_typed_stored_attributes? || _local_typed_stored_attributes[store_name].empty?
127
- _store_local_stored_attribute(store_name, name, type, **options)
127
+ _local_typed_stored_attributes[store_name][name] = [type, options]
128
128
  end
129
129
 
130
130
  def store_attribute_unset_values_fallback_to_default
@@ -138,11 +138,6 @@ module ActiveRecord
138
138
  end
139
139
  end
140
140
 
141
- def _store_local_stored_attribute(store_name, key, cast_type, default: Type::TypedStore::UNDEFINED, **options) # :nodoc:
142
- cast_type = ActiveRecord::Type.lookup(cast_type, **options) if cast_type.is_a?(Symbol)
143
- _local_typed_stored_attributes[store_name][key] = [cast_type, default]
144
- end
145
-
146
141
  def _local_typed_stored_attributes?
147
142
  instance_variable_defined?(:@local_typed_stored_attributes)
148
143
  end
@@ -177,7 +172,9 @@ module ActiveRecord
177
172
  type = Type::TypedStore.create_from_type(subtype)
178
173
  type.owner = owner
179
174
  defaultik.type = type
180
- subtypes.each { |name, (cast_type, default)| type.add_typed_key(name, cast_type, default: default) }
175
+ subtypes.each do |name, (cast_type, options)|
176
+ type.add_typed_key(name, cast_type, **options.symbolize_keys)
177
+ end
181
178
 
182
179
  define_default_attribute(attr_name, defaultik.proc, type, from_user: true)
183
180
 
@@ -191,7 +188,9 @@ module ActiveRecord
191
188
  type = Type::TypedStore.create_from_type(subtype)
192
189
  type.owner = owner
193
190
  defaultik.type = type
194
- subtypes.each { |name, (cast_type, default)| type.add_typed_key(name, cast_type, default: default) }
191
+ subtypes.each do |name, (cast_type, options)|
192
+ type.add_typed_key(name, cast_type, **options.symbolize_keys)
193
+ end
195
194
 
196
195
  type
197
196
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module StoreAttribute # :nodoc:
4
- VERSION = "1.1.0"
4
+ VERSION = "1.1.1"
5
5
  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.1.0
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - palkan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-03-08 00:00:00.000000000 Z
11
+ date: 2023-06-27 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.6
109
+ rubygems_version: 3.4.8
110
110
  signing_key:
111
111
  specification_version: 4
112
112
  summary: ActiveRecord extension which adds typecasting to store accessors