active_typed_store 1.3.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.lock +1 -1
- data/lib/active_typed_store/attrs.rb +16 -18
- data/lib/active_typed_store/store.rb +12 -0
- data/lib/active_typed_store/version.rb +1 -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: 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.lock
CHANGED
@@ -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
|
|
@@ -41,32 +42,29 @@ module ActiveTypedStore
|
|
41
42
|
end
|
42
43
|
|
43
44
|
private def reader(store_attribute, field, type, default)
|
44
|
-
ivar_prev
|
45
|
-
|
45
|
+
ivar_prev = :"@__ts_prev_#{field}"
|
46
|
+
|
46
47
|
store_module.define_method(field) do
|
47
48
|
val = read_store_attribute(store_attribute, field)
|
48
|
-
return instance_variable_get(ivar_cache) if instance_variable_get(ivar_prev) == val && !val.nil?
|
49
49
|
|
50
|
-
|
50
|
+
casted_val =
|
51
51
|
if val.nil? && !default.nil?
|
52
|
-
|
53
|
-
self[store_attribute][field] =
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
end
|
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
|
61
60
|
elsif type.respond_to?(:cast)
|
62
61
|
casted = type.cast(val)
|
63
|
-
casted.eql?(val) ? val : casted
|
62
|
+
casted.eql?(val) ? val : (self[store_attribute][field] = casted)
|
64
63
|
else
|
65
|
-
type[val]
|
64
|
+
self[store_attribute][field] = type[val]
|
66
65
|
end
|
67
66
|
|
68
|
-
instance_variable_set(ivar_prev,
|
69
|
-
instance_variable_set(ivar_cache, cache_val)
|
67
|
+
instance_variable_set(ivar_prev, casted_val)
|
70
68
|
end
|
71
69
|
end
|
72
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
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_typed_store
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 2.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ermolaev Andrey
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-05-
|
11
|
+
date: 2025-05-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|