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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0b7b0080eb6128847d7f71444d31f97bd2b4d09ebd9e0611901867e6a7812b1d
4
- data.tar.gz: b3f85301fb398025f1cd732987035def7a79ba743fe51f9c1df337a1992848bd
3
+ metadata.gz: cfb874f973a7bd4611949cd39c064ce2de1a06bf2a7cd68fc526ef7c41f0c3e4
4
+ data.tar.gz: d7c7f3b56c0c247c5f73610e537f6a39a435cade4e67ce93cf29f6a856301968
5
5
  SHA512:
6
- metadata.gz: 30312348d528402aa1fb3da6c00c0f12cd9cc13fb76d1f5f2a9410d908c69aecf2eadb662d7a243f6fa486bbea093c78de8b8a0806a91390da1c9f75c4e4b0fd
7
- data.tar.gz: 485c25f17feda5fdaeab8d105f923470ed28a13f73c07c851854dc6af86a86d1dcf044598748ca3a2abdca1eb64d3550734a017a941ebb64373cda8eaf10b296
6
+ metadata.gz: f70971458fa4e3833058cf3904a070374ced50507a033b3bc619bdbb0f8a0623f9fd61da4ae967c11d71853874296ddf5801f152cf0ec9f18be614cc27d1c961
7
+ data.tar.gz: 2f737173b83cc355772c6d66f760b5bc56faead1fbdc63d4d0cb2d63d37a8a1c24eed79e8a69b5dd7e1f3088b2bd3374b8b30316688e06a72b38f76621b208aa
@@ -2,5 +2,5 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  module AssociateJsonb
5
- VERSION = "0.0.2"
5
+ VERSION = "0.0.3"
6
6
  end
@@ -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
- given = super(given || {}).with_indifferent_access
120
- write_attribute(:#{attribute}, given["#{key}"])
121
- given["#{key}"] = #{attribute} unless #{attribute}.nil?
122
- super(given)
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)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: associate_jsonb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sampson Crowley