active_typed_store 2.0.0 → 2.1.0
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 +4 -4
- data/Gemfile +0 -1
- data/Gemfile.lock +7 -8
- data/lib/active_typed_store/attrs.rb +15 -26
- data/lib/active_typed_store/store.rb +12 -0
- data/lib/active_typed_store/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 284ddabdbf758d07bc56e984971ef1cf058633a663e9a6f50072f3d795fe76cf
|
4
|
+
data.tar.gz: 52cb762351e5e2132d1f3f7c16b034449474f63cb0641ddc6d7c67cb5b9778fa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0ff0bf66c6037e2124e2bf5513070b6dc5035afb3770457db1e729b755486828ae9cb447ce62828f94707480a08e18d164437d5961b0a0589c94e353e3396082
|
7
|
+
data.tar.gz: 59b389d92a4582c6824444e874c6c20279461d467e7454e6a59ad8c5e3f705c15069f0c5d1613d593ea283614d26d261ba20c971634c81169f0840e2a0e8896d
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -22,7 +22,7 @@ GIT
|
|
22
22
|
PATH
|
23
23
|
remote: .
|
24
24
|
specs:
|
25
|
-
active_typed_store (1.
|
25
|
+
active_typed_store (2.1.0)
|
26
26
|
activemodel
|
27
27
|
activerecord
|
28
28
|
activesupport
|
@@ -63,11 +63,6 @@ GEM
|
|
63
63
|
concurrent-ruby (~> 1.0)
|
64
64
|
dry-core (~> 1.0, < 2)
|
65
65
|
zeitwerk (~> 2.6)
|
66
|
-
dry-struct (1.6.0)
|
67
|
-
dry-core (~> 1.0, < 2)
|
68
|
-
dry-types (>= 1.7, < 2)
|
69
|
-
ice_nine (~> 0.11)
|
70
|
-
zeitwerk (~> 2.6)
|
71
66
|
dry-types (1.7.2)
|
72
67
|
bigdecimal (~> 3.0)
|
73
68
|
concurrent-ruby (~> 1.0)
|
@@ -77,7 +72,6 @@ GEM
|
|
77
72
|
zeitwerk (~> 2.6)
|
78
73
|
i18n (1.14.5)
|
79
74
|
concurrent-ruby (~> 1.0)
|
80
|
-
ice_nine (0.11.2)
|
81
75
|
json (2.7.2)
|
82
76
|
language_server-protocol (3.17.0.3)
|
83
77
|
logger (1.6.1)
|
@@ -137,6 +131,8 @@ GEM
|
|
137
131
|
rumoji (0.5.0)
|
138
132
|
securerandom (0.3.1)
|
139
133
|
sqlite3 (1.7.3-arm64-darwin)
|
134
|
+
sqlite3 (1.7.3-x86_64-darwin)
|
135
|
+
sqlite3 (1.7.3-x86_64-linux)
|
140
136
|
timeout (0.4.1)
|
141
137
|
tzinfo (2.0.6)
|
142
138
|
concurrent-ruby (~> 1.0)
|
@@ -144,11 +140,14 @@ GEM
|
|
144
140
|
zeitwerk (2.6.18)
|
145
141
|
|
146
142
|
PLATFORMS
|
143
|
+
arm64-darwin-21
|
144
|
+
arm64-darwin-23
|
147
145
|
arm64-darwin-24
|
146
|
+
x86_64-darwin-21
|
147
|
+
x86_64-linux
|
148
148
|
|
149
149
|
DEPENDENCIES
|
150
150
|
active_typed_store!
|
151
|
-
dry-struct
|
152
151
|
dry-types
|
153
152
|
priscilla!
|
154
153
|
rake (~> 13.0)
|
@@ -28,7 +28,8 @@ module ActiveTypedStore
|
|
28
28
|
# dry_type[nil] для optional типов возвращает не default-значение, а nil
|
29
29
|
reader(attr_name, field, type, (type.value if type.default?))
|
30
30
|
else
|
31
|
-
|
31
|
+
writer(attr_name, field, type)
|
32
|
+
reader(attr_name, field, type, default)
|
32
33
|
end
|
33
34
|
end
|
34
35
|
|
@@ -42,40 +43,28 @@ module ActiveTypedStore
|
|
42
43
|
|
43
44
|
private def reader(store_attribute, field, type, default)
|
44
45
|
ivar_prev = :"@__ts_prev_#{field}"
|
46
|
+
|
45
47
|
store_module.define_method(field) do
|
46
48
|
val = read_store_attribute(store_attribute, field)
|
47
|
-
return val if instance_variable_get(ivar_prev) == val.object_id && !val.nil?
|
48
49
|
|
49
|
-
is_default = false
|
50
50
|
casted_val =
|
51
51
|
if val.nil? && !default.nil?
|
52
|
-
|
53
|
-
|
52
|
+
v = default.dup
|
53
|
+
self[store_attribute][field] = v
|
54
|
+
clear_attribute_change(store_attribute)
|
55
|
+
self[store_attribute][field] = v
|
56
|
+
elsif val.nil?
|
57
|
+
return nil
|
58
|
+
elsif instance_variable_get(ivar_prev).eql?(val)
|
59
|
+
return val
|
54
60
|
elsif type.respond_to?(:cast)
|
55
|
-
type.cast(val)
|
61
|
+
casted = type.cast(val)
|
62
|
+
casted.eql?(val) ? val : (self[store_attribute][field] = casted)
|
56
63
|
else
|
57
|
-
type[val]
|
58
|
-
end
|
59
|
-
|
60
|
-
return_val =
|
61
|
-
if casted_val.eql?(val)
|
62
|
-
val
|
63
|
-
else
|
64
|
-
is_changed = attribute_changed?(store_attribute)
|
65
|
-
|
66
|
-
# write cast val
|
67
|
-
self[store_attribute][field] = casted_val
|
68
|
-
|
69
|
-
# discard changes
|
70
|
-
if !is_changed && (val == casted_val || is_default)
|
71
|
-
@attributes.write_from_database(store_attribute, self[store_attribute].to_json).value[field]
|
72
|
-
else
|
73
|
-
casted_val
|
74
|
-
end
|
64
|
+
self[store_attribute][field] = type[val]
|
75
65
|
end
|
76
66
|
|
77
|
-
instance_variable_set(ivar_prev,
|
78
|
-
return_val
|
67
|
+
instance_variable_set(ivar_prev, casted_val)
|
79
68
|
end
|
80
69
|
end
|
81
70
|
end
|
@@ -2,10 +2,22 @@
|
|
2
2
|
|
3
3
|
module ActiveTypedStore
|
4
4
|
module Store
|
5
|
+
class CustomJson < ActiveRecord::Type::Json
|
6
|
+
def changed_in_place?(raw_old_value, new_value)
|
7
|
+
deserialize(raw_old_value) != new_value.as_json
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
5
11
|
def typed_store(store_attribute, &)
|
6
12
|
attrs = Attrs.new(store_attribute)
|
7
13
|
attrs.instance_eval(&)
|
8
14
|
|
15
|
+
# for redefined self._default_attributes
|
16
|
+
def self.type_for_column(connection, column) # rubocop:disable Lint/NestedMethodDefinition
|
17
|
+
return ActiveTypedStore::Store::CustomJson.new if column.name == "params"
|
18
|
+
|
19
|
+
super
|
20
|
+
end
|
9
21
|
store_accessor store_attribute, attrs.fields
|
10
22
|
|
11
23
|
if ActiveTypedStore.config.hash_safety == :disallow_symbol_keys
|