jsonb_accessor 1.3.4 → 1.3.6
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/.github/workflows/ci.yml +2 -1
- data/CHANGELOG.md +10 -0
- data/README.md +1 -1
- data/lib/jsonb_accessor/attribute_query_methods.rb +2 -2
- data/lib/jsonb_accessor/helpers.rb +14 -0
- data/lib/jsonb_accessor/macro.rb +11 -9
- data/lib/jsonb_accessor/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: b9c291219f0d8fa746d82718410e4eb6743a2e53b0c7f55b2d4770b0ab40b4de
|
|
4
|
+
data.tar.gz: 92cb5a1e680f3bcab2aff0ad1c459e1f67714083337a1cf0675837aba3f01a65
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: cf6c29dba63cdc774387bc4e8146b7884188ef6219e29a901367cc380da7257501401a4788534016ea6c8c95a1a2cfb526e8657ae6f8606caa4e91748c4358dd
|
|
7
|
+
data.tar.gz: f8805f9278ca28e29b2521b3283e132e2264687a5dfaee01c18de82ede3de38465228092a96571bbb66d24a24cd3a01b5d61732ef2cbacca75fc02679860eb39
|
data/.github/workflows/ci.yml
CHANGED
data/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,16 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
## [Unreleased]
|
|
3
3
|
|
|
4
|
+
## [1.3.6] - 2022-09-23
|
|
5
|
+
### Fixed
|
|
6
|
+
|
|
7
|
+
- Bug fix: Datetime values were not properly deserialized [#155](https://github.com/madeintandem/jsonb_accessor/pull/155)
|
|
8
|
+
|
|
9
|
+
## [1.3.5] - 2022-07-23
|
|
10
|
+
### Fixed
|
|
11
|
+
|
|
12
|
+
- Bug fix: Attributes defined outside of jsonb_accessor are not written [#149](https://github.com/madeintandem/jsonb_accessor/pull/149)
|
|
13
|
+
|
|
4
14
|
## [1.3.4] - 2022-02-02
|
|
5
15
|
### Fixed
|
|
6
16
|
|
data/README.md
CHANGED
|
@@ -11,13 +11,13 @@ module JsonbAccessor
|
|
|
11
11
|
|
|
12
12
|
# <jsonb_attribute>_where scope
|
|
13
13
|
klass.define_singleton_method "#{jsonb_attribute}_where" do |attributes|
|
|
14
|
-
store_key_attributes =
|
|
14
|
+
store_key_attributes = JsonbAccessor::Helpers.convert_keys_to_store_keys(attributes, all.model.public_send(store_key_mapping_method_name))
|
|
15
15
|
jsonb_where(jsonb_attribute, store_key_attributes)
|
|
16
16
|
end
|
|
17
17
|
|
|
18
18
|
# <jsonb_attribute>_where_not scope
|
|
19
19
|
klass.define_singleton_method "#{jsonb_attribute}_where_not" do |attributes|
|
|
20
|
-
store_key_attributes =
|
|
20
|
+
store_key_attributes = JsonbAccessor::Helpers.convert_keys_to_store_keys(attributes, all.model.public_send(store_key_mapping_method_name))
|
|
21
21
|
jsonb_where_not(jsonb_attribute, store_key_attributes)
|
|
22
22
|
end
|
|
23
23
|
|
|
@@ -19,5 +19,19 @@ module JsonbAccessor
|
|
|
19
19
|
def convert_store_keys_to_keys(attributes, store_key_mapping)
|
|
20
20
|
convert_keys_to_store_keys(attributes, store_key_mapping.invert)
|
|
21
21
|
end
|
|
22
|
+
|
|
23
|
+
def deserialize_value(value, attribute_type)
|
|
24
|
+
return value if value.blank?
|
|
25
|
+
|
|
26
|
+
if attribute_type == :datetime
|
|
27
|
+
value = if active_record_default_timezone == :utc
|
|
28
|
+
Time.find_zone("UTC").parse(value).in_time_zone
|
|
29
|
+
else
|
|
30
|
+
Time.zone.parse(value)
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
value
|
|
35
|
+
end
|
|
22
36
|
end
|
|
23
37
|
end
|
data/lib/jsonb_accessor/macro.rb
CHANGED
|
@@ -38,7 +38,7 @@ module JsonbAccessor
|
|
|
38
38
|
end
|
|
39
39
|
|
|
40
40
|
# Get store keys to default values mapping
|
|
41
|
-
store_keys_and_defaults =
|
|
41
|
+
store_keys_and_defaults = JsonbAccessor::Helpers.convert_keys_to_store_keys(names_and_defaults, public_send(store_key_mapping_method_name))
|
|
42
42
|
|
|
43
43
|
# Define jsonb_defaults_mapping_for_<jsonb_attribute>
|
|
44
44
|
defaults_mapping_method_name = "jsonb_defaults_mapping_for_#{jsonb_attribute}"
|
|
@@ -69,7 +69,7 @@ module JsonbAccessor
|
|
|
69
69
|
attribute_value = public_send(name)
|
|
70
70
|
# Rails always saves time based on `default_timezone`. Since #as_json considers timezone, manual conversion is needed
|
|
71
71
|
if attribute_value.acts_like?(:time)
|
|
72
|
-
attribute_value = (
|
|
72
|
+
attribute_value = (JsonbAccessor::Helpers.active_record_default_timezone == :utc ? attribute_value.utc : attribute_value.in_time_zone).strftime("%F %R:%S.%L")
|
|
73
73
|
end
|
|
74
74
|
|
|
75
75
|
new_values = (public_send(jsonb_attribute) || {}).merge(store_key => attribute_value)
|
|
@@ -83,17 +83,16 @@ module JsonbAccessor
|
|
|
83
83
|
names_to_store_keys = self.class.public_send(store_key_mapping_method_name)
|
|
84
84
|
|
|
85
85
|
# this is the raw hash we want to save in the jsonb_attribute
|
|
86
|
-
value_with_store_keys =
|
|
86
|
+
value_with_store_keys = JsonbAccessor::Helpers.convert_keys_to_store_keys(value, names_to_store_keys)
|
|
87
87
|
write_attribute(jsonb_attribute, value_with_store_keys)
|
|
88
88
|
|
|
89
89
|
# this maps attributes to values
|
|
90
|
-
value_with_named_keys =
|
|
90
|
+
value_with_named_keys = JsonbAccessor::Helpers.convert_store_keys_to_keys(value, names_to_store_keys)
|
|
91
91
|
|
|
92
92
|
empty_named_attributes = names_to_store_keys.transform_values { nil }
|
|
93
93
|
empty_named_attributes.merge(value_with_named_keys).each do |name, attribute_value|
|
|
94
|
-
#
|
|
95
|
-
|
|
96
|
-
next unless has_attribute? name
|
|
94
|
+
# Only proceed if this attribute has been defined using `jsonb_accessor`.
|
|
95
|
+
next unless names_to_store_keys.key?(name)
|
|
97
96
|
|
|
98
97
|
write_attribute(name, attribute_value)
|
|
99
98
|
end
|
|
@@ -110,12 +109,15 @@ module JsonbAccessor
|
|
|
110
109
|
name = names_and_store_keys.key(store_key)
|
|
111
110
|
next unless name
|
|
112
111
|
|
|
113
|
-
write_attribute(
|
|
112
|
+
write_attribute(
|
|
113
|
+
name,
|
|
114
|
+
JsonbAccessor::Helpers.deserialize_value(value, self.class.type_for_attribute(name).type)
|
|
115
|
+
)
|
|
114
116
|
clear_attribute_change(name) if persisted?
|
|
115
117
|
end
|
|
116
118
|
end
|
|
117
119
|
|
|
118
|
-
|
|
120
|
+
JsonbAccessor::AttributeQueryMethods.new(self).define(store_key_mapping_method_name, jsonb_attribute)
|
|
119
121
|
end
|
|
120
122
|
end
|
|
121
123
|
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: jsonb_accessor
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.3.
|
|
4
|
+
version: 1.3.6
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Michael Crismali
|
|
@@ -10,7 +10,7 @@ authors:
|
|
|
10
10
|
autorequire:
|
|
11
11
|
bindir: exe
|
|
12
12
|
cert_chain: []
|
|
13
|
-
date: 2022-
|
|
13
|
+
date: 2022-09-23 00:00:00.000000000 Z
|
|
14
14
|
dependencies:
|
|
15
15
|
- !ruby/object:Gem::Dependency
|
|
16
16
|
name: activerecord
|