attr_json 1.4.0 → 2.6.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.
Files changed (40) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ci.yml +22 -22
  3. data/.github/workflows/future_rails_ci.yml +3 -3
  4. data/Appraisals +40 -29
  5. data/CHANGELOG.md +144 -1
  6. data/Gemfile +8 -2
  7. data/README.md +83 -63
  8. data/attr_json.gemspec +8 -7
  9. data/doc_src/forms.md +3 -14
  10. data/gemfiles/rails_6_0.gemfile +3 -2
  11. data/gemfiles/rails_6_1.gemfile +2 -2
  12. data/gemfiles/rails_7_0.gemfile +2 -3
  13. data/gemfiles/{rails_5_1.gemfile → rails_7_1.gemfile} +4 -4
  14. data/gemfiles/{rails_5_2.gemfile → rails_7_2.gemfile} +4 -4
  15. data/gemfiles/{rails_5_0.gemfile → rails_8_0.gemfile} +5 -6
  16. data/gemfiles/rails_8_1.gemfile +18 -0
  17. data/gemfiles/rails_edge.gemfile +4 -4
  18. data/lib/attr_json/attribute_definition/registry.rb +43 -9
  19. data/lib/attr_json/attribute_definition.rb +51 -14
  20. data/lib/attr_json/config.rb +1 -2
  21. data/lib/attr_json/model/nested_model_validator.rb +27 -0
  22. data/lib/attr_json/model.rb +185 -53
  23. data/lib/attr_json/nested_attributes/builder.rb +2 -0
  24. data/lib/attr_json/nested_attributes/multiparameter_attribute_writer.rb +2 -0
  25. data/lib/attr_json/nested_attributes/writer.rb +6 -6
  26. data/lib/attr_json/nested_attributes.rb +7 -1
  27. data/lib/attr_json/record/query_builder.rb +2 -0
  28. data/lib/attr_json/record/query_scopes.rb +2 -0
  29. data/lib/attr_json/record.rb +113 -88
  30. data/lib/attr_json/serialization_coder_from_type.rb +2 -0
  31. data/lib/attr_json/type/array.rb +12 -3
  32. data/lib/attr_json/type/container_attribute.rb +2 -0
  33. data/lib/attr_json/type/model.rb +15 -4
  34. data/lib/attr_json/type/polymorphic_model.rb +43 -23
  35. data/lib/attr_json/version.rb +1 -1
  36. data/lib/attr_json.rb +21 -6
  37. data/playground_models.rb +2 -2
  38. metadata +15 -32
  39. data/doc_src/dirty_tracking.md +0 -155
  40. data/lib/attr_json/record/dirty.rb +0 -281
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b2f8a06eaf0058564901292a35bf15fd56c24b0eb8cb784ab1b1e9adc94b87e5
4
- data.tar.gz: eb4917f0eb8304b8261536ae75a5abd64dfc29aed52d82c190bb9b48a738ff08
3
+ metadata.gz: c998ba03c0014b885521c0887f43dc0e1fcda328d61aa50921eea04b4a82b1aa
4
+ data.tar.gz: '0813b424db2bceb7c9466c404d71822541fd9262b5add2412f9bd4cabdf8bc91'
5
5
  SHA512:
6
- metadata.gz: 599a5e752e187a9e511b766efffda2bbf546c6940f42e58c2f0cb883ef835c017e4ec8b9a4fbc2a3236fde733ae6c77c8d27e4728b0fff53dc993b209a3d7882
7
- data.tar.gz: 84dac19bcebedf7979ad3299b28ecc175fec59887cc9e6d761d708f0dbb240f8443aba52aca89a434ab8040f5ff64288ce4a428a659c61e8ff11d128399b5974
6
+ metadata.gz: 955e14e84be8141072680b2c33f89fa58ccfb720f006737ffbf708b38116f1fd80d9b45158d9e0b85ca2df76479f002aa96990bbce1cb7e63335162eadad7e23
7
+ data.tar.gz: 11a651f067c931301568b11f06f3c38f53ce93c1625320debf98ee5174b8c97b11b2756f1a6d539e7c83af78e9c68021e4ede43aa0880d6bdb8e45f658aa5029
@@ -18,7 +18,10 @@ jobs:
18
18
  tests:
19
19
  services:
20
20
  db:
21
- image: postgres:9.4
21
+ # used to be 9.4, should work on 9.4, only moved to 10.0
22
+ # because of rails 7.1 bug (rails intends to support 9 too!)
23
+ # https://github.com/jrochkind/attr_json/issues/211
24
+ image: postgres:10.0
22
25
  env:
23
26
  POSTGRES_USER: postgres
24
27
  POSTGRES_PASSWORD: postgres
@@ -29,24 +32,6 @@ jobs:
29
32
  fail-fast: false
30
33
  matrix:
31
34
  include:
32
- - gemfile: rails_5_0
33
- ruby: 2.4
34
-
35
- - gemfile: rails_5_0
36
- ruby: 2.5
37
-
38
- - gemfile: rails_5_1
39
- ruby: 2.4
40
-
41
- - gemfile: rails_5_2
42
- ruby: 2.4
43
-
44
- - gemfile: rails_5_2
45
- ruby: 2.6
46
-
47
- - gemfile: rails_6_0
48
- ruby: 2.6
49
-
50
35
  - gemfile: rails_6_0
51
36
  ruby: 2.7
52
37
 
@@ -54,15 +39,30 @@ jobs:
54
39
  ruby: 2.7
55
40
 
56
41
  - gemfile: rails_6_1
57
- ruby: 3.0
42
+ ruby: '3.0'
58
43
 
59
44
  - gemfile: rails_7_0
60
- ruby: 3.0
45
+ ruby: 3.1
46
+
47
+ - gemfile: rails_7_0
48
+ ruby: 3.2
49
+
50
+ - gemfile: rails_7_1
51
+ ruby: 3.3
52
+
53
+ - gemfile: rails_7_2
54
+ ruby: 3.3
55
+
56
+ - gemfile: rails_8_0
57
+ ruby: 3.3
58
+
59
+ - gemfile: rails_8_1
60
+ ruby: 3.4
61
61
 
62
62
  name: ${{ matrix.gemfile }}, ruby ${{ matrix.ruby }}
63
63
 
64
64
  steps:
65
- - uses: actions/checkout@v2
65
+ - uses: actions/checkout@v4
66
66
 
67
67
  - name: Set up Ruby
68
68
  uses: ruby/setup-ruby@v1
@@ -31,7 +31,7 @@ jobs:
31
31
  tests:
32
32
  services:
33
33
  db:
34
- image: postgres:9.4
34
+ image: postgres:10.0
35
35
  env:
36
36
  POSTGRES_USER: postgres
37
37
  POSTGRES_PASSWORD: postgres
@@ -45,12 +45,12 @@ jobs:
45
45
  include:
46
46
 
47
47
  - gemfile: rails_edge
48
- ruby: 2.7
48
+ ruby: '3.3'
49
49
 
50
50
  name: ${{ matrix.gemfile }}, ruby ${{ matrix.ruby }}
51
51
 
52
52
  steps:
53
- - uses: actions/checkout@v2
53
+ - uses: actions/checkout@v3
54
54
 
55
55
  - name: Set up Ruby
56
56
  uses: ruby/setup-ruby@v1
data/Appraisals CHANGED
@@ -1,64 +1,75 @@
1
- appraise "rails-5-0" do
2
- gem 'combustion', '~> 0.9.0'
1
+ appraise "rails-6-0" do
2
+ gem 'combustion', "~> 1.0"
3
3
 
4
- gem "rails", "~> 5.0.0"
4
+ gem "rails", ">= 6.0.0", "< 6.1"
5
+ gem "pg", "~> 1.0"
6
+ gem "rspec-rails", "~> 5.0"
5
7
 
6
- # rails 5.1+ includes it by default, but rails 5.0 needs it:
7
- gem 'rails-ujs', require: false
8
8
 
9
- # Rails 5 won't work with pg 1.0 even though it doesn't say so
10
- gem "pg", "~> 0.18"
9
+ # Ruby 2.7 still needs webdrivers, since it can't use a new enough
10
+ # version of selenium-webdriver to download drivers itself
11
+ gem "webdrivers", ">= 5.3.1"
11
12
  end
12
13
 
13
- appraise "rails-5-1" do
14
- gem 'combustion', '~> 0.9.0'
15
-
16
- gem "rails", "~> 5.1.0"
14
+ appraise "rails-6-1" do
15
+ gem 'combustion', "~> 1.0"
17
16
 
17
+ gem "rails", "~> 6.1.0"
18
18
  gem "pg", "~> 1.0"
19
+
20
+ # sprockets-rails is already a rails 6.1 dependency, but combustion is failing
21
+ # to require it, this is one way to get it required.
22
+ # https://github.com/pat/combustion/issues/128
23
+ gem "sprockets-rails"
19
24
  end
20
25
 
21
- appraise "rails-5-2" do
22
- gem 'combustion', '~> 0.9.0'
26
+ appraise "rails-7-0" do
27
+ gem 'combustion', "~> 1.0"
23
28
 
24
- gem "rails", "~> 5.2.0"
29
+ gem "rails", "~> 7.0.0"
25
30
  gem "pg", "~> 1.0"
26
31
  end
27
32
 
28
- appraise "rails-6-0" do
33
+ appraise "rails-7-1" do
29
34
  gem 'combustion', "~> 1.0"
30
35
 
31
- gem "rails", ">= 6.0.0", "< 6.1"
36
+ gem "rails", "~> 7.1.0"
32
37
  gem "pg", "~> 1.0"
33
38
  end
34
39
 
35
- appraise "rails-6-1" do
40
+ appraise "rails-7-2" do
36
41
  gem 'combustion', "~> 1.0"
37
42
 
38
- gem "rails", "~> 6.1.0"
43
+ gem "rails", "~> 7.2.0"
39
44
  gem "pg", "~> 1.0"
40
45
  end
41
46
 
42
- appraise "rails-7-0" do
47
+ appraise "rails-8-0" do
43
48
  gem 'combustion', "~> 1.0"
44
49
 
45
- gem "rails", "~> 7.0.0"
50
+ gem "rails", "~> 8.0.0"
46
51
  gem "pg", "~> 1.0"
52
+ end
47
53
 
48
- # to make our integration tests using simple_form work as-is,
49
- # this works. Don't totally underestand the actual simple_form
50
- # setup paths in Rails 7....
51
- gem "sprockets-rails"
54
+ appraise "rails-8-1" do
55
+ gem 'combustion', "~> 1.0"
56
+
57
+ gem "rails", "~> 8.1.0"
58
+ gem "pg", "~> 1.0"
52
59
  end
53
60
 
61
+
54
62
  appraise "rails-edge" do
55
- gem 'combustion', "~> 1.0"
63
+ # need combustion edge to work with rails edge, will no longer
64
+ # be true on next combustion release, probably no later than Rails 7.1
65
+ # https://github.com/pat/combustion/pull/126
66
+ gem 'combustion', "~> 1.0", github: "pat/combustion"
56
67
 
57
68
  gem "rails", git: "https://github.com/rails/rails.git", branch: "main"
58
69
  gem "pg", "~> 1.0"
59
70
 
60
- # We do some tests using cocoon, currently via sprockets-rails,
61
- # which is not automatically available in Rails 7. Not sure
62
- # the future of cocoon in general. https://github.com/nathanvda/cocoon/issues/555
63
- gem "sprockets-rails"
71
+ # Edge rails, future Rails 7.1 currently allows rack 3 -- but rails itself
72
+ # and some of our other dependencies may not actually work with rack 3 yet,
73
+ # let's test under rack 2. (Nothing in this gem deals with levels as low as rack)
74
+ gem "rack", "~> 2.0"
64
75
  end
data/CHANGELOG.md CHANGED
@@ -4,10 +4,153 @@ 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/v1.4.0...HEAD)
8
7
 
8
+ ## [Unreleased](https://github.com/jrochkind/attr_json/compare/v2.6.0...HEAD)
9
9
 
10
+ ### Fixed
11
+
12
+ *
13
+
14
+ *
15
+
16
+ *
17
+
18
+ ### Added
19
+
20
+ *
21
+
22
+ *
23
+
24
+ ### Changed
25
+
26
+ *
27
+
28
+ *
29
+
30
+ *
31
+
32
+ ## [2.6.0](https://github.com/jrochkind/attr_json/compare/v2.5.1...v2.6.0)
33
+
34
+ * Allow Rails 8.1, no logic changes.
35
+
36
+ ## [2.5.1](https://github.com/jrochkind/attr_json/compare/v2.5.0...v2.5.1)
37
+
38
+ ## Fixed
39
+
40
+ * Fixed bug where date/datetime types required db to exist on app boot. https://github.com/jrochkind/attr_json/pull/242 Thanks @jNicker
41
+
42
+
43
+ ## [2.5.0](https://github.com/jrochkind/attr_json/compare/v2.4.0...v2.5.0)
44
+
45
+ ## Added
46
+
47
+ * Allow Rails 8.0 in gemspec (no code changes required to support) https://github.com/jrochkind/attr_json/pull/236
48
+
49
+ ## [2.4.0](https://github.com/jrochkind/attr_json/compare/v2.3.1...v2.4.0)
50
+
51
+ ### Added
52
+
53
+ * Allow Rails 7.2 in gemspec (no code changes required to support) https://github.com/jrochkind/attr_json/pull/228
54
+
55
+ ## [2.3.1](https://github.com/jrochkind/attr_json/compare/v2.3.0...v2.3.1)
56
+
57
+ ### Fixed
58
+
59
+ * Keep nested model validation working in Rails post-7.1, by no longer trying to re-use ActiveRecord::Validations::AssociatedValidator, instead supplying our own custom code. https://github.com/jrochkind/attr_json/pull/220
60
+
61
+ * Validate PolymorphicModel instances. https://github.com/jrochkind/attr_json/pull/225 Thanks @LyricL-Gitster
62
+
63
+
64
+ ## [2.3.0]((https://github.com/jrochkind/attr_json/compare/v2.2.0...v2.3.0))
65
+
66
+
67
+ ### Changed
68
+
69
+ * Avoid private ActiveRecord API when lazily registering container attributes. (Compat with Rails post 7.1) https://github.com/jrochkind/attr_json/pull/214
70
+
71
+ * Freeze more strings to reduce String allocations https://github.com/jrochkind/attr_json/pull/216
72
+
73
+ ## [2.2.0](https://github.com/jrochkind/attr_json/compare/v2.1.0...v2.2.0)
74
+
75
+ ### Added
76
+
77
+ * Test and allow Rails 7.1 https://github.com/jrochkind/attr_json/pull/208 Thanks @JoeSouthan
78
+
79
+
80
+ ## [2.1.0](https://github.com/jrochkind/attr_json/compare/v2.0.1...v2.1.0)
81
+
82
+ ### Added
83
+
84
+ * Support for `store_key` in models used with polymorphic model feature. https://github.com/jrochkind/attr_json/pull/206 . Thanks @rdubya
85
+
86
+
87
+ ## [2.0.1](https://github.com/jrochkind/attr_json/compare/v2.0.0...v2.0.1)
88
+
89
+
90
+ ### Fixed
91
+
92
+ * 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
93
+
94
+ ### Changed
95
+
96
+ * Refactor #attr_json_sync_to_rails_attributes for slightly improved performance. https://github.com/jrochkind/attr_json/pull/192
97
+
98
+ * Safety guard in sync_to_rails_attributes against unknown edge case where container is nil https://github.com/jrochkind/attr_json/pull/194
99
+
100
+
101
+ ## [2.0.0](https://github.com/jrochkind/attr_json/compare/v1.5.0...v2.0.0)
102
+
103
+ While it has some backwards incompat changes, this is expected not to be a challenging upgrade, please let us know by filing an issue if it's giving you troubles, maybe we can make things easier for you. No changes to data stored in your DB should be needed when upgrading, the persisted data should be compatible between 1.x and 2.x.
104
+
105
+ ### Removed
106
+
107
+ * `AttrJson::Record::Dirty` has been removed, along with the `#attr_json_changes` method. You should now be able to just use standard ActiveRecord dirty tracking with attr_json attributes. https://github.com/jrochkind/attr_json/pull/163 (AttrJson::Record::Dirty was actually badly broken, as reported by @bemueller at https://github.com/jrochkind/attr_json/issues/148)
108
+
109
+ * The `rails_attribute` param to `attr_json` or `attr_json_config` no longer exists. We now always create rails attributes for AttrJson::Record attributes. https://github.com/jrochkind/attr_json/pull/117 and https://github.com/jrochkind/attr_json/pull/158
110
+
111
+ ### Changed
112
+
113
+ * We now create Rails Attribute cover for all attr_json attributes, and we do a better job of keeping the Rails attribute values sync'd with attr_json values. https://github.com/jrochkind/attr_json/pull/117, https://github.com/jrochkind/attr_json/pull/158, and https://github.com/jrochkind/attr_json/pull/163
114
+
115
+ * Drop support for Rails earlier than 6.0 and ruby earlier than 2.7. https://github.com/jrochkind/attr_json/pull/155 https://github.com/jrochkind/attr_json/pull/174
116
+
117
+ * Array types now default to an empty array. If you'd like to turn that off, you can use the somewhat odd `default: AttrJson::AttributeDefinition::NO_DEFAULT_PROVIDED` on attribute definiton. Thanks @g13ydson for suggestion. https://github.com/jrochkind/attr_json/pull/161
118
+
119
+ * time or datetime types used to truncate all fractional seconds to 0. Now they properly allow precision of `ActiveSupport::JSON::Encoding.time_precision` (normally three decimal places, ie milliseconds). And by default the Type::Value's are set to proper precision for cast too. https://github.com/jrochkind/attr_json/pull/173
120
+
121
+ * AttrJson::Models are serialized without nil values in the hash, for more compact representations. This is only done for attributes without defaults. This behavior can be disabled/altered when specifying the type. https://github.com/jrochkind/attr_json/pull/175
122
+
123
+ * config default_accepts_nested_attributes will only apply nested attributes to suitable attribute types (array or nested model), the default won't apply to inapplicable types. https://github.com/jrochkind/attr_json/pull/178
124
+
125
+ ### Added
126
+
127
+ * ActiveRecord-style "timezone-aware attribute" conversion now works properly, in both AttrJson::Record and (similarly) AttrJson::Model. https://github.com/jrochkind/attr_json/pull/164
128
+
129
+ ### Fixed
130
+
131
+ * the `AttrJson::Type::Array` type used for our array types was not properly tracking in-place mutation changes. Now it is https://github.com/jrochkind/attr_json/pull/163
132
+
133
+ * Default nested model validation should allow nils in arrays of models. https://github.com/jrochkind/attr_json/pull/177
134
+
135
+
136
+
137
+ ## [1.5.0](https://github.com/jrochkind/attr_json/compare/v1.4.1...v1.5.0)
138
+
139
+ ### Added
140
+
141
+ * AttrJson::Model#dup will properly deep-dup attributes https://github.com/jrochkind/attr_json/pull/169
142
+
143
+ * AttrJson::Model#freeze will freeze attributes -- but not deep-freeze. https://github.com/jrochkind/attr_json/pull/169
144
+
145
+ * AttrJson::Model has some methods conventional in ActiveModel classes: Klass.attribute_types, Klass.attribute_names, and instance.attribute_names. https://github.com/jrochkind/attr_json/pull/169
146
+
147
+
148
+
149
+ ## [1.4.1](https://github.com/jrochkind/attr_json/compare/v1.4.0...v1.4.1)
150
+
151
+ ### Fixed
10
152
 
153
+ * Fixed an obscure bug involving a conflict between attribute defaults and accepts_nested_attributes, in which defaults could overwrite assigned attributes. The `.fill_in_defaults` class method, which was never intended as public API and was commented accordingly, is gone. https://github.com/jrochkind/attr_json/pull/160
11
154
 
12
155
  ## [1.4.0](https://github.com/jrochkind/attr_json/compare/v1.3.0...v1.4.0)
13
156
 
data/Gemfile CHANGED
@@ -19,7 +19,7 @@ gem 'combustion', '~> 1.1'
19
19
  gem 'rails'
20
20
 
21
21
  gem "pg"
22
- gem "rspec-rails", "~> 4.0"
22
+ gem "rspec-rails", "~> 6.0"
23
23
  gem "simple_form", ">= 4.0"
24
24
  gem 'cocoon', ">= 1.2"
25
25
  gem 'jquery-rails'
@@ -29,8 +29,14 @@ gem 'jquery-rails'
29
29
  # don't understand, so we need to depend on it.
30
30
  gem "coffee-rails"
31
31
 
32
+ # We do some tests using cocoon via sprockets, which needs sprockets-rails,
33
+ # which is not automatically available in Rails 7. We add it explicitly,
34
+ # which will duplciate dependences in rails pre-7, but add for rails 7. Not sure
35
+ # the future of cocoon in general. https://github.com/nathanvda/cocoon/issues/555
36
+ gem "sprockets-rails"
37
+
38
+
32
39
  gem 'capybara', "~> 3.0"
33
- gem 'webdrivers', '~> 4.0'
34
40
  gem "selenium-webdriver"
35
41
 
36
42
  gem "byebug"