associate_jsonb 0.0.2 → 0.0.3
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/lib/associate_jsonb/version.rb +1 -1
- data/lib/associate_jsonb/with_store_attribute.rb +17 -4
- 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: cfb874f973a7bd4611949cd39c064ce2de1a06bf2a7cd68fc526ef7c41f0c3e4
|
4
|
+
data.tar.gz: d7c7f3b56c0c247c5f73610e537f6a39a435cade4e67ce93cf29f6a856301968
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f70971458fa4e3833058cf3904a070374ced50507a033b3bc619bdbb0f8a0623f9fd61da4ae967c11d71853874296ddf5801f152cf0ec9f18be614cc27d1c961
|
7
|
+
data.tar.gz: 2f737173b83cc355772c6d66f760b5bc56faead1fbdc63d4d0cb2d63d37a8a1c24eed79e8a69b5dd7e1f3088b2bd3374b8b30316688e06a72b38f76621b208aa
|
@@ -106,6 +106,15 @@ module AssociateJsonb
|
|
106
106
|
is_array \
|
107
107
|
? "write_attribute(:#{attribute}, Array(given))" \
|
108
108
|
: "super(given)"
|
109
|
+
on_store_change = ->(var) {
|
110
|
+
"write_attribute(:#{attribute}, #{
|
111
|
+
is_array \
|
112
|
+
? "Array(#{var})" \
|
113
|
+
: var
|
114
|
+
})"
|
115
|
+
}
|
116
|
+
|
117
|
+
|
109
118
|
if is_array
|
110
119
|
mixin.class_eval <<-CODE, __FILE__, __LINE__ + 1
|
111
120
|
def #{attribute}
|
@@ -116,10 +125,14 @@ module AssociateJsonb
|
|
116
125
|
|
117
126
|
mixin.class_eval <<-CODE, __FILE__, __LINE__ + 1
|
118
127
|
def #{store}=(given)
|
119
|
-
|
120
|
-
write_attribute(:#{attribute},
|
121
|
-
|
122
|
-
|
128
|
+
super(given || {})
|
129
|
+
write_attribute(:#{attribute}, #{on_store_change.call %Q(#{store}["#{key}"])})
|
130
|
+
if #{attribute}.blank?
|
131
|
+
#{store}.delete("#{key}")
|
132
|
+
else
|
133
|
+
#{store}["#{key}"] = #{attribute}
|
134
|
+
end
|
135
|
+
#{store}
|
123
136
|
end
|
124
137
|
|
125
138
|
def #{attribute}=(given)
|