attr_json 2.3.0 → 2.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: eb4f8078039ec81cc25e7a95318ff5e42cb5bf85a955b40326f60f9022af16a2
4
- data.tar.gz: 635f08ce5fa34ce45dfdd5256ae0e81fdcc2d455f4525bad5f71f5b0c4391c6b
3
+ metadata.gz: 158f20e87ae0be8aae9c5421c587380d5c9404c1df7271634fd20c607f10c823
4
+ data.tar.gz: 470d5fc5cdd5f8a2c797765f0a3cefe1c138026c8684ea9fb20c1883ed1566ca
5
5
  SHA512:
6
- metadata.gz: 22c35f674c7b5f3a4e91f348d20439df3e8fe175ca5d3c8938720a5e71739df2474cdddd5fdab5f0527f8751ed0fb6dee11ba7f75889c143daca92bd84afc86b
7
- data.tar.gz: 636628f0083dd61c869de5b9eb65a0c11988560e26d5dcd8e822759788bdac4bdb3c6f0359e2257867ac91a61721fda32df54a36f51a001450ef883289be433a
6
+ metadata.gz: 3e33cf6fb2b71be270c938395b6c453a8311519f0a875372534677c2f7bc9a2a15311dec666ab7d93b4a7fe0f4da36996cded7862fd9cf1b01a89100ce3bfaf6
7
+ data.tar.gz: d4eed5840a55e7d98158e1bd3b70b9f082b114f6dc389d532547d93d776684602ba896c297abc0f124d10a24821ad4eb13ef0036c1d9ac0771b198d30b868a2e
@@ -62,10 +62,16 @@ jobs:
62
62
  - gemfile: rails_7_1
63
63
  ruby: 3.2
64
64
 
65
+ - gemfile: rails_7_1
66
+ ruby: 3.3
67
+
68
+ - gemfile: rails_7_2
69
+ ruby: 3.3
70
+
65
71
  name: ${{ matrix.gemfile }}, ruby ${{ matrix.ruby }}
66
72
 
67
73
  steps:
68
- - uses: actions/checkout@v3
74
+ - uses: actions/checkout@v4
69
75
 
70
76
  - name: Set up Ruby
71
77
  uses: ruby/setup-ruby@v1
@@ -45,7 +45,7 @@ jobs:
45
45
  include:
46
46
 
47
47
  - gemfile: rails_edge
48
- ruby: '3.1'
48
+ ruby: '3.3'
49
49
 
50
50
  name: ${{ matrix.gemfile }}, ruby ${{ matrix.ruby }}
51
51
 
data/Appraisals CHANGED
@@ -37,6 +37,14 @@ appraise "rails-7-1" do
37
37
  gem "pg", "~> 1.0"
38
38
  end
39
39
 
40
+ appraise "rails-7-2" do
41
+ gem 'combustion', "~> 1.0"
42
+
43
+ gem "rails", "~> 7.2.0"
44
+ gem "pg", "~> 1.0"
45
+ end
46
+
47
+
40
48
  appraise "rails-edge" do
41
49
  # need combustion edge to work with rails edge, will no longer
42
50
  # be true on next combustion release, probably no later than Rails 7.1
data/CHANGELOG.md CHANGED
@@ -4,7 +4,8 @@ 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.3.0...HEAD)
7
+
8
+ ## [Unreleased](https://github.com/jrochkind/attr_json/compare/v2.3.1...HEAD)
8
9
 
9
10
  ### Fixed
10
11
 
@@ -30,6 +31,22 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
30
31
 
31
32
  *
32
33
 
34
+ ## [2.3.1](https://github.com/jrochkind/attr_json/compare/v2.3.1...v2.4.0)
35
+
36
+ ### Added
37
+
38
+ * Allow Rails 7.2 in gemspec (no code changes required to support) https://github.com/jrochkind/attr_json/pull/228
39
+
40
+
41
+ ## [2.3.1](https://github.com/jrochkind/attr_json/compare/v2.3.0...v2.3.1)
42
+
43
+ ### Fixed
44
+
45
+ * 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
46
+
47
+ * Validate PolymorphicModel instances. https://github.com/jrochkind/attr_json/pull/225 Thanks @LyricL-Gitster
48
+
49
+
33
50
  ## [2.3.0]((https://github.com/jrochkind/attr_json/compare/v2.2.0...v2.3.0))
34
51
 
35
52
 
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # AttrJson
2
- [![CI Status](https://github.com/jrochkind/attr_json/workflows/CI/badge.svg?branch=master)](https://github.com/jrochkind/attr_json/actions?query=workflow%3ACI+branch%3Amaster)
3
- [![CI Status](https://github.com/jrochkind/attr_json/workflows/CI%20on%20Future%20Rails%20Versions/badge.svg?branch=master)](https://github.com/jrochkind/attr_json/actions?query=workflow%3A%22CI+on+Future+Rails+Versions%22+branch%3Amaster)
2
+ [![CI Status](https://github.com/jrochkind/attr_json/workflows/CI/badge.svg?branch=master)](https://github.com/jrochkind/attr_json/actions/workflows/ci.yml?query=workflow%3ACI+branch%3Amaster)
3
+ [![CI Status](https://github.com/jrochkind/attr_json/workflows/CI%20on%20Future%20Rails%20Versions/badge.svg?branch=master)](https://github.com/jrochkind/attr_json/actions/workflows/future_rails_ci.yml?query=workflow%3ACI+branch%3Amaster)
4
4
  [![Gem Version](https://badge.fury.io/rb/attr_json.svg)](https://badge.fury.io/rb/attr_json)
5
5
 
6
6
  ActiveRecord attributes stored serialized in a json column, super smooth. For Rails 6.0.x through 7.0.x. Ruby 2.7+.
data/attr_json.gemspec CHANGED
@@ -47,7 +47,7 @@ attributes use as much of the existing ActiveRecord architecture as we can.}
47
47
  # dependency included just as it is here, should never be released
48
48
  # from an env tht has any of these variables set.
49
49
  unless ENV['APPRAISAL_INITIALIZED'] || ENV["TRAVIS"] || ENV['CI']
50
- spec.add_runtime_dependency "activerecord", ">= 6.0.0", "< 7.2"
50
+ spec.add_runtime_dependency "activerecord", ">= 6.0.0", "< 7.3"
51
51
  end
52
52
 
53
53
  spec.add_development_dependency "bundler"
@@ -0,0 +1,18 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "combustion", "~> 1.0"
6
+ gem "rails", "~> 7.2.0"
7
+ gem "pg", "~> 1.0"
8
+ gem "rspec-rails", "~> 6.0"
9
+ gem "simple_form", ">= 4.0"
10
+ gem "cocoon", ">= 1.2"
11
+ gem "jquery-rails"
12
+ gem "coffee-rails"
13
+ gem "sprockets-rails"
14
+ gem "capybara", "~> 3.0"
15
+ gem "selenium-webdriver"
16
+ gem "byebug"
17
+
18
+ gemspec path: "../"
@@ -0,0 +1,27 @@
1
+ module AttrJson
2
+ module Model
3
+ # Used to validate an attribute in an AttrJson::Model whose values are other models, when
4
+ # you want validation errors on the nested models to post up.
5
+ #
6
+ # This is based on ActiveRecord's own ActiveRecord::Validations::AssociatedValidator, and actually forked
7
+ # from it at https://github.com/rails/rails/blob/e37adfed4eff3b43350ec87222a922e9c72d9c1b/activerecord/lib/active_record/validations/associated.rb
8
+ #
9
+ # We used to simply use an ActiveRecord::Validations::AssociatedValidator, but as of https://github.com/jrochkind/attr_json/pull/220 (e1e798142d)
10
+ # it got ActiveRecord-specific functionality that no longer worked with our use case.
11
+ #
12
+ # No problem, the implementation is simple, we can provide it here, based on the last version that did work.
13
+ class NestedModelValidator < ActiveModel::EachValidator
14
+ def validate_each(record, attribute, value)
15
+ if Array(value).reject { |r| valid_object?(r) }.any?
16
+ record.errors.add(attribute, :invalid, **options.merge(value: value))
17
+ end
18
+ end
19
+
20
+ private
21
+ def valid_object?(record)
22
+ #(record.respond_to?(:marked_for_destruction?) && record.marked_for_destruction?) || record.valid?
23
+ record.valid?
24
+ end
25
+ end
26
+ end
27
+ end
@@ -8,6 +8,7 @@ require 'attr_json/attribute_definition/registry'
8
8
 
9
9
  require 'attr_json/type/model'
10
10
  require 'attr_json/model/cocoon_compat'
11
+ require 'attr_json/model/nested_model_validator'
11
12
 
12
13
  require 'attr_json/serialization_coder_from_type'
13
14
 
@@ -207,8 +208,8 @@ module AttrJson
207
208
  # @option options [String,Symbol] :store_key (nil) Serialize to JSON using
208
209
  # given store_key, rather than name as would be usual.
209
210
  #
210
- # @option options [Boolean] :validate (true) Create an ActiveRecord::Validations::AssociatedValidator so
211
- # validation errors on the attributes post up to self.
211
+ # @option options [Boolean] :validate (true) Mak validation errors on the attributes post up
212
+ # to self, using something similar to an ActiveRecord::Validations::AssociatedValidator
212
213
  def attr_json(name, type, **options)
213
214
  options.assert_valid_keys(*(AttributeDefinition::VALID_OPTIONS - [:container_attribute] + [:validate]))
214
215
 
@@ -219,10 +220,9 @@ module AttrJson
219
220
  )
220
221
 
221
222
  # By default, automatically validate nested models
222
- if type.kind_of?(AttrJson::Type::Model) && options[:validate] != false
223
- # Yes. we're passing an ActiveRecord::Validations validator, but
224
- # it works fine for ActiveModel. If this changes in the future, tests will catch.
225
- self.validates_with ActiveRecord::Validations::AssociatedValidator, attributes: [name.to_sym]
223
+ if (type.kind_of?(AttrJson::Type::Model) || type.kind_of?(AttrJson::Type::PolymorphicModel)) && options[:validate] != false
224
+ # Post validations up with something based on ActiveRecord::Validations::AssociatedValidator
225
+ self.validates_with ::AttrJson::Model::NestedModelValidator, attributes: [name.to_sym]
226
226
  end
227
227
 
228
228
  _attr_jsons_module.module_eval do
@@ -1,3 +1,3 @@
1
1
  module AttrJson
2
- VERSION = "2.3.0"
2
+ VERSION = "2.4.0"
3
3
  end
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.3.0
4
+ version: 2.4.0
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-12-04 00:00:00.000000000 Z
11
+ date: 2024-08-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -19,7 +19,7 @@ dependencies:
19
19
  version: 6.0.0
20
20
  - - "<"
21
21
  - !ruby/object:Gem::Version
22
- version: '7.2'
22
+ version: '7.3'
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
@@ -29,7 +29,7 @@ dependencies:
29
29
  version: 6.0.0
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
- version: '7.2'
32
+ version: '7.3'
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: bundler
35
35
  requirement: !ruby/object:Gem::Requirement
@@ -165,6 +165,7 @@ files:
165
165
  - gemfiles/rails_6_1.gemfile
166
166
  - gemfiles/rails_7_0.gemfile
167
167
  - gemfiles/rails_7_1.gemfile
168
+ - gemfiles/rails_7_2.gemfile
168
169
  - gemfiles/rails_edge.gemfile
169
170
  - lib/attr_json.rb
170
171
  - lib/attr_json/attribute_definition.rb
@@ -172,6 +173,7 @@ files:
172
173
  - lib/attr_json/config.rb
173
174
  - lib/attr_json/model.rb
174
175
  - lib/attr_json/model/cocoon_compat.rb
176
+ - lib/attr_json/model/nested_model_validator.rb
175
177
  - lib/attr_json/nested_attributes.rb
176
178
  - lib/attr_json/nested_attributes/builder.rb
177
179
  - lib/attr_json/nested_attributes/multiparameter_attribute_writer.rb
@@ -207,7 +209,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
207
209
  - !ruby/object:Gem::Version
208
210
  version: '0'
209
211
  requirements: []
210
- rubygems_version: 3.4.21
212
+ rubygems_version: 3.2.33
211
213
  signing_key:
212
214
  specification_version: 4
213
215
  summary: ActiveRecord attributes stored serialized in a json column, super smooth.