attr_json 2.0.0 → 2.0.1
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/Appraisals +0 -6
- data/CHANGELOG.md +15 -2
- data/gemfiles/rails_edge.gemfile +0 -2
- data/lib/attr_json/record.rb +23 -13
- data/lib/attr_json/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cd9c25a736bb3b1ce26527c555718efcff2967204d853962048ffc2471af243c
|
4
|
+
data.tar.gz: dc022d69b43b4576d2939bb90f2e172b65b8dd45708b361758554561dc61f44f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6457f06b9aed14481b7dd1543929d7010b54d232473f64cde811452083279ab72bbeb92f7a972e903d8994f21f3e263c5163044aa363db4c35a7eadd42710f24
|
7
|
+
data.tar.gz: 8dd0bad4eb89aad50ceb084ecb48a08d0f4b19d67f9421250fb808a2238c159fce891d1e07d37568b6ba6c65c284a9b2b600e1156cf32334a2c7d518d468994d
|
data/Appraisals
CHANGED
@@ -37,11 +37,5 @@ appraise "rails-edge" do
|
|
37
37
|
# Edge rails, future Rails 7.1 currently allows rack 3 -- but rails itself
|
38
38
|
# and some of our other dependencies may not actually work with rack 3 yet,
|
39
39
|
# let's test under rack 2. (Nothing in this gem deals with levels as low as rack)
|
40
|
-
#
|
41
|
-
# Bundler was having trouble resolving unless we specified rackup and rack-session
|
42
|
-
# limits too, I think it was a bundler failure, we actually only care about
|
43
|
-
# rack < 3 here.
|
44
40
|
gem "rack", "~> 2.0"
|
45
|
-
gem "rackup", "< 2"
|
46
|
-
gem "rack-session", "< 2"
|
47
41
|
end
|
data/CHANGELOG.md
CHANGED
@@ -4,9 +4,9 @@ Notable changes to this project will be documented in this file.
|
|
4
4
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
5
5
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
6
6
|
|
7
|
-
## [Unreleased](https://github.com/jrochkind/attr_json/compare/v2.0.
|
7
|
+
## [Unreleased](https://github.com/jrochkind/attr_json/compare/v2.0.1...HEAD)
|
8
8
|
|
9
|
-
###
|
9
|
+
### Fixed
|
10
10
|
|
11
11
|
*
|
12
12
|
|
@@ -22,6 +22,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
22
22
|
|
23
23
|
*
|
24
24
|
|
25
|
+
## [2.0.1](https://github.com/jrochkind/attr_json/compare/v2.0.0...v2.0.1)
|
26
|
+
|
27
|
+
|
28
|
+
### Fixed
|
29
|
+
|
30
|
+
* You can now do a specified ActiveRecord `.select` without your json containers, to fetch an object with other attributes that you can access. https://github.com/jrochkind/attr_json/pull/193
|
31
|
+
|
32
|
+
### Changed
|
33
|
+
|
34
|
+
* Refactor #attr_json_sync_to_rails_attributes for slightly improved performance. https://github.com/jrochkind/attr_json/pull/192
|
35
|
+
|
36
|
+
* Safety guard in sync_to_rails_attributes against unknown edge case where container is nil https://github.com/jrochkind/attr_json/pull/194
|
37
|
+
|
25
38
|
|
26
39
|
## [2.0.0](https://github.com/jrochkind/attr_json/compare/v1.5.0...v2.0.0)
|
27
40
|
|
data/gemfiles/rails_edge.gemfile
CHANGED
data/lib/attr_json/record.rb
CHANGED
@@ -48,23 +48,33 @@ module AttrJson
|
|
48
48
|
# mutation of mutable object will effect both places, for instance for dirty
|
49
49
|
# tracking.
|
50
50
|
def attr_json_sync_to_rails_attributes
|
51
|
-
self.class.attr_json_registry.
|
51
|
+
self.class.attr_json_registry.definitions.group_by(&:container_attribute).each_pair do |container_attribute, definitions|
|
52
52
|
begin
|
53
|
-
|
54
|
-
|
55
|
-
value = json_value[attribute_def.store_key]
|
53
|
+
# column may have eg been left out of an explicit 'select'
|
54
|
+
next unless has_attribute?(container_attribute)
|
56
55
|
|
57
|
-
|
58
|
-
# TODO, can we just make this use the setter?
|
59
|
-
write_attribute(attr_name, value)
|
56
|
+
container_value = public_send(container_attribute)
|
60
57
|
|
61
|
-
|
58
|
+
# isn't expected to be possible to be nil rather than empty hash, but
|
59
|
+
# if it is from some edge case, well, we don't have values to sync, fine
|
60
|
+
next if container_value.nil?
|
62
61
|
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
62
|
+
definitions.each do |attribute_def|
|
63
|
+
attr_name = attribute_def.name
|
64
|
+
value = container_value[attribute_def.store_key]
|
65
|
+
|
66
|
+
if value
|
67
|
+
# TODO, can we just make this use the setter?
|
68
|
+
write_attribute(attr_name, value)
|
69
|
+
|
70
|
+
clear_attribute_change(attr_name) if persisted?
|
71
|
+
|
72
|
+
# writing and clearning will result in a new object stored in
|
73
|
+
# rails attributes, we want
|
74
|
+
# to make sure the exact same object is in the json attribute,
|
75
|
+
# so in-place mutation changes to it are reflected in both places.
|
76
|
+
container_value[attribute_def.store_key] = read_attribute(attr_name)
|
77
|
+
end
|
68
78
|
end
|
69
79
|
rescue AttrJson::Type::Model::BadCast, AttrJson::Type::PolymorphicModel::TypeError => e
|
70
80
|
# There was bad data in the DB, we're just going to skip the Rails attribute sync.
|
data/lib/attr_json/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: attr_json
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jonathan Rochkind
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-02-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -206,7 +206,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
206
206
|
- !ruby/object:Gem::Version
|
207
207
|
version: '0'
|
208
208
|
requirements: []
|
209
|
-
rubygems_version: 3.
|
209
|
+
rubygems_version: 3.3.26
|
210
210
|
signing_key:
|
211
211
|
specification_version: 4
|
212
212
|
summary: ActiveRecord attributes stored serialized in a json column, super smooth.
|