attr_json 0.2.0 → 1.5.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.
- checksums.yaml +5 -5
- data/.github/workflows/ci.yml +87 -0
- data/.github/workflows/future_rails_ci.yml +66 -0
- data/.gitignore +1 -0
- data/Appraisals +62 -0
- data/CHANGELOG.md +67 -0
- data/Gemfile +38 -35
- data/README.md +161 -36
- data/attr_json.gemspec +27 -4
- data/doc_src/dirty_tracking.md +1 -1
- data/doc_src/forms.md +76 -14
- data/gemfiles/.bundle/config +2 -0
- data/gemfiles/rails_5_0.gemfile +20 -0
- data/gemfiles/rails_5_1.gemfile +19 -0
- data/gemfiles/rails_5_2.gemfile +19 -0
- data/gemfiles/rails_6_0.gemfile +19 -0
- data/gemfiles/rails_6_1.gemfile +19 -0
- data/gemfiles/rails_7_0.gemfile +19 -0
- data/gemfiles/rails_edge.gemfile +19 -0
- data/lib/attr_json/attribute_definition/registry.rb +6 -1
- data/lib/attr_json/attribute_definition.rb +15 -2
- data/lib/attr_json/config.rb +55 -0
- data/lib/attr_json/model.rb +125 -42
- data/lib/attr_json/nested_attributes/writer.rb +26 -1
- data/lib/attr_json/nested_attributes.rb +7 -1
- data/lib/attr_json/record/dirty.rb +19 -13
- data/lib/attr_json/record/query_builder.rb +15 -3
- data/lib/attr_json/record/query_scopes.rb +6 -0
- data/lib/attr_json/record.rb +120 -32
- data/lib/attr_json/serialization_coder_from_type.rb +40 -0
- data/lib/attr_json/type/array.rb +6 -0
- data/lib/attr_json/type/container_attribute.rb +14 -3
- data/lib/attr_json/type/model.rb +38 -8
- data/lib/attr_json/type/polymorphic_model.rb +7 -0
- data/lib/attr_json/version.rb +1 -1
- data/lib/attr_json.rb +1 -1
- metadata +61 -21
- data/.travis.yml +0 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 3cd2566fed014325bee56f5c062080d3c929a790dbb3b287e92b086c2fa3180f
|
4
|
+
data.tar.gz: ffa8e7b471dce27a2708b12e6a2bf27edb5b20d1345656ca026ecc4b263a01a7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f8db6d4211a2dd9f4b9d8a5482b723597958082617e139157c325e8e3b9dddf15216d21bd56daece5d5b3674acdc8e099a22998ad452473a4bf0834774b7a21f
|
7
|
+
data.tar.gz: 13e2cd5b4b10f67f4ecfc1be8732c6a33a7f7a7fdb561b6d8f4f89ae39c74e4b0b153ae10fdf5d650a239534f5b28cd33750aaff90009eeec8877677e765a935
|
@@ -0,0 +1,87 @@
|
|
1
|
+
name: CI
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
branches: [ master ]
|
6
|
+
pull_request:
|
7
|
+
branches: [ '**' ]
|
8
|
+
# UTC Tuesdays 0900. note, no notifications will be sent for failed scheduled builds. :(
|
9
|
+
schedule:
|
10
|
+
- cron: '0 9 * * TUE'
|
11
|
+
|
12
|
+
|
13
|
+
env:
|
14
|
+
POSTGRES_USER: postgres
|
15
|
+
POSTGRES_PASSWORD: postgres
|
16
|
+
|
17
|
+
jobs:
|
18
|
+
tests:
|
19
|
+
services:
|
20
|
+
db:
|
21
|
+
image: postgres:9.4
|
22
|
+
env:
|
23
|
+
POSTGRES_USER: postgres
|
24
|
+
POSTGRES_PASSWORD: postgres
|
25
|
+
ports: ['5432:5432']
|
26
|
+
|
27
|
+
runs-on: ubuntu-latest
|
28
|
+
strategy:
|
29
|
+
fail-fast: false
|
30
|
+
matrix:
|
31
|
+
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
|
+
- gemfile: rails_6_0
|
51
|
+
ruby: 2.7
|
52
|
+
|
53
|
+
- gemfile: rails_6_1
|
54
|
+
ruby: 2.7
|
55
|
+
|
56
|
+
- gemfile: rails_6_1
|
57
|
+
ruby: '3.0'
|
58
|
+
|
59
|
+
- gemfile: rails_7_0
|
60
|
+
ruby: '3.0'
|
61
|
+
|
62
|
+
- gemfile: rails_7_0
|
63
|
+
ruby: 3.1
|
64
|
+
|
65
|
+
- gemfile: rails_7_0
|
66
|
+
ruby: 3.2
|
67
|
+
|
68
|
+
|
69
|
+
name: ${{ matrix.gemfile }}, ruby ${{ matrix.ruby }}
|
70
|
+
|
71
|
+
steps:
|
72
|
+
- uses: actions/checkout@v3
|
73
|
+
|
74
|
+
- name: Set up Ruby
|
75
|
+
uses: ruby/setup-ruby@v1
|
76
|
+
with:
|
77
|
+
ruby-version: ${{ matrix.ruby }}
|
78
|
+
bundler-cache: false
|
79
|
+
|
80
|
+
- name: Bundle install
|
81
|
+
run: |
|
82
|
+
bundle config set gemfile "${GITHUB_WORKSPACE}/gemfiles/${{ matrix.gemfile }}.gemfile"
|
83
|
+
bundle install --jobs 4 --retry 3
|
84
|
+
|
85
|
+
- name: Run tests
|
86
|
+
run: |
|
87
|
+
bundle exec rspec
|
@@ -0,0 +1,66 @@
|
|
1
|
+
name: CI on Future Rails Versions
|
2
|
+
|
3
|
+
# Experimenting with separate github actions workflow
|
4
|
+
# for gemfiles for FUTURE Rails vesions, we'd like to keep an eye on
|
5
|
+
# if they pass, but they aren't required to do so.
|
6
|
+
#
|
7
|
+
# This has to just be a copy-and-paste copy of our main ci.yml,
|
8
|
+
# but with different gemfiles in the matrix. That is not great.
|
9
|
+
# We also choose NOT to run this one on pull_request, we just
|
10
|
+
# run it on master, see how that works.
|
11
|
+
#
|
12
|
+
# These jobs can be left out of "required" for merge in github settings
|
13
|
+
# for "Branch Protection Rules" at https://github.com/jrochkind/attr_json/settings/branches
|
14
|
+
#
|
15
|
+
# You can move a Rails version between this file and ci.yml, and (un)check it in those
|
16
|
+
# github settings. (I wish whether it was required to pass could be in this file
|
17
|
+
# too, to keep things together)
|
18
|
+
|
19
|
+
on:
|
20
|
+
push:
|
21
|
+
branches: [ master ]
|
22
|
+
# UTC Sundays 0900. note, no notifications will be sent for failed scheduled builds. :(
|
23
|
+
schedule:
|
24
|
+
- cron: '0 9 * * SUN'
|
25
|
+
|
26
|
+
env:
|
27
|
+
POSTGRES_USER: postgres
|
28
|
+
POSTGRES_PASSWORD: postgres
|
29
|
+
|
30
|
+
jobs:
|
31
|
+
tests:
|
32
|
+
services:
|
33
|
+
db:
|
34
|
+
image: postgres:9.4
|
35
|
+
env:
|
36
|
+
POSTGRES_USER: postgres
|
37
|
+
POSTGRES_PASSWORD: postgres
|
38
|
+
ports: ['5432:5432']
|
39
|
+
|
40
|
+
runs-on: ubuntu-latest
|
41
|
+
|
42
|
+
strategy:
|
43
|
+
fail-fast: false
|
44
|
+
matrix:
|
45
|
+
include:
|
46
|
+
|
47
|
+
- gemfile: rails_edge
|
48
|
+
ruby: '3.1'
|
49
|
+
|
50
|
+
name: ${{ matrix.gemfile }}, ruby ${{ matrix.ruby }}
|
51
|
+
|
52
|
+
steps:
|
53
|
+
- uses: actions/checkout@v3
|
54
|
+
|
55
|
+
- name: Set up Ruby
|
56
|
+
uses: ruby/setup-ruby@v1
|
57
|
+
with:
|
58
|
+
ruby-version: ${{ matrix.ruby }}
|
59
|
+
|
60
|
+
- name: Bundle install
|
61
|
+
run: |
|
62
|
+
bundle config set gemfile "${GITHUB_WORKSPACE}/gemfiles/${{ matrix.gemfile }}.gemfile"
|
63
|
+
bundle install --jobs 4 --retry 3
|
64
|
+
|
65
|
+
- name: Run tests
|
66
|
+
run: bundle exec rspec
|
data/.gitignore
CHANGED
data/Appraisals
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
appraise "rails-5-0" do
|
2
|
+
gem 'combustion', '~> 0.9.0'
|
3
|
+
|
4
|
+
gem "rails", "~> 5.0.0"
|
5
|
+
|
6
|
+
# rails 5.1+ includes it by default, but rails 5.0 needs it:
|
7
|
+
gem 'rails-ujs', require: false
|
8
|
+
|
9
|
+
# Rails 5 won't work with pg 1.0 even though it doesn't say so
|
10
|
+
gem "pg", "~> 0.18"
|
11
|
+
end
|
12
|
+
|
13
|
+
appraise "rails-5-1" do
|
14
|
+
gem 'combustion', '~> 0.9.0'
|
15
|
+
|
16
|
+
gem "rails", "~> 5.1.0"
|
17
|
+
|
18
|
+
gem "pg", "~> 1.0"
|
19
|
+
end
|
20
|
+
|
21
|
+
appraise "rails-5-2" do
|
22
|
+
gem 'combustion', '~> 0.9.0'
|
23
|
+
|
24
|
+
gem "rails", "~> 5.2.0"
|
25
|
+
gem "pg", "~> 1.0"
|
26
|
+
end
|
27
|
+
|
28
|
+
appraise "rails-6-0" do
|
29
|
+
gem 'combustion', "~> 1.0"
|
30
|
+
|
31
|
+
gem "rails", ">= 6.0.0", "< 6.1"
|
32
|
+
gem "pg", "~> 1.0"
|
33
|
+
end
|
34
|
+
|
35
|
+
appraise "rails-6-1" do
|
36
|
+
gem 'combustion', "~> 1.0"
|
37
|
+
|
38
|
+
gem "rails", "~> 6.1.0"
|
39
|
+
gem "pg", "~> 1.0"
|
40
|
+
|
41
|
+
# sprockets-rails is already a rails 6.1 dependency, but combustion is failing
|
42
|
+
# to require it, this is one way to get it required.
|
43
|
+
# https://github.com/pat/combustion/issues/128
|
44
|
+
gem "sprockets-rails"
|
45
|
+
end
|
46
|
+
|
47
|
+
appraise "rails-7-0" do
|
48
|
+
gem 'combustion', "~> 1.0"
|
49
|
+
|
50
|
+
gem "rails", "~> 7.0.0"
|
51
|
+
gem "pg", "~> 1.0"
|
52
|
+
end
|
53
|
+
|
54
|
+
appraise "rails-edge" do
|
55
|
+
# need combustion edge to work with rails edge, will no longer
|
56
|
+
# be true on next combustion release, probably no later than Rails 7.1
|
57
|
+
# https://github.com/pat/combustion/pull/126
|
58
|
+
gem 'combustion', "~> 1.0", github: "pat/combustion"
|
59
|
+
|
60
|
+
gem "rails", git: "https://github.com/rails/rails.git", branch: "main"
|
61
|
+
gem "pg", "~> 1.0"
|
62
|
+
end
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
# Changelog
|
2
|
+
Notable changes to this project will be documented in this file.
|
3
|
+
|
4
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
5
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
6
|
+
|
7
|
+
## [Unreleased](https://github.com/jrochkind/attr_json/compare/v1.4.1...HEAD)
|
8
|
+
|
9
|
+
|
10
|
+
## [1.5.0](https://github.com/jrochkind/attr_json/compare/v1.4.1...v1.5.0)
|
11
|
+
|
12
|
+
### Added
|
13
|
+
|
14
|
+
* AttrJson::Model#dup will properly deep-dup attributes https://github.com/jrochkind/attr_json/pull/169
|
15
|
+
|
16
|
+
* AttrJson::Model#freeze will freeze attributes -- but not deep-freeze. https://github.com/jrochkind/attr_json/pull/169
|
17
|
+
|
18
|
+
* 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
|
19
|
+
|
20
|
+
## [1.4.1](https://github.com/jrochkind/attr_json/compare/v1.4.0...v1.4.1)
|
21
|
+
|
22
|
+
### Fixed
|
23
|
+
|
24
|
+
* 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
|
25
|
+
|
26
|
+
## [1.4.0](https://github.com/jrochkind/attr_json/compare/v1.3.0...v1.4.0)
|
27
|
+
|
28
|
+
### Changed
|
29
|
+
|
30
|
+
* When using store_key feature on an AttrJson::Model, you should not be able to pass in the store_key as a key in initializer or assign_attributes. It was really a bug that this ended up mapped to attribute this way, which could cause a problem in some cases; but calling it out in Changed section because if you were accidentally relying on it, it may appear as a backwards incompat to you. https://github.com/jrochkind/attr_json/pull/125
|
31
|
+
|
32
|
+
* Rails 7.0.0 allowed by gemspec and tested in CI
|
33
|
+
|
34
|
+
### Fixed
|
35
|
+
|
36
|
+
* polymorphic single type can be set to nil https://github.com/jrochkind/attr_json/pull/115
|
37
|
+
* polymorphic models can be serialized from hash in container attribute. Thanks @machty. https://github.com/jrochkind/attr_json/pull/123
|
38
|
+
* fix bug with deserialization of nested attributes that have types that apply different serialization vs cast logic. Thanks @bradleesand. https://github.com/jrochkind/attr_json/pull/125
|
39
|
+
|
40
|
+
## [1.3.0](https://github.com/jrochkind/attr_json/compare/v1.2.0...v1.3.0)
|
41
|
+
|
42
|
+
### Added
|
43
|
+
|
44
|
+
* Gemspec allows use with ActiveRecord 6.1.x
|
45
|
+
|
46
|
+
## [1.2.0](https://github.com/jrochkind/attr_json/compare/v1.1.0...v1.2.0)
|
47
|
+
|
48
|
+
### Added
|
49
|
+
|
50
|
+
* attr_json_config(bad_cast: :as_nil) to avoid raising on data that can't be cast to a
|
51
|
+
AttrJson::Model, instead just casting to nil. https://github.com/jrochkind/attr_json/pull/95
|
52
|
+
|
53
|
+
* Documented and tested support for using ActiveRecord serialize to map one AttrJson::Model
|
54
|
+
to an entire column on it's own. https://github.com/jrochkind/attr_json/pull/89 and
|
55
|
+
https://github.com/jrochkind/attr_json/pull/93
|
56
|
+
|
57
|
+
* Better synchronization with ActiveRecord attributes when using rails_attribute:true, and a configurable true default_rails_attribute. Thanks @volkanunsal . https://github.com/jrochkind/attr_json/pull/94
|
58
|
+
|
59
|
+
### Changed
|
60
|
+
|
61
|
+
* AttrJson::Model#== now requires same class for equality. And doesn't raise on certain arguments. https://github.com/jrochkind/attr_json/pull/90 Thanks @caiofilipemr for related bug report.
|
62
|
+
|
63
|
+
## [1.1.0](https://github.com/jrochkind/attr_json/compare/v1.0.0...v1.1.0)
|
64
|
+
|
65
|
+
### Added
|
66
|
+
|
67
|
+
* not_jsonb_contains query method, like `jsonb_contains` but negated. https://github.com/jrochkind/attr_json/pull/85
|
data/Gemfile
CHANGED
@@ -3,40 +3,43 @@ source 'https://rubygems.org'
|
|
3
3
|
# Specify your gem's dependencies in attr_json.gemspec
|
4
4
|
gemspec
|
5
5
|
|
6
|
-
# for
|
7
|
-
#
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
6
|
+
# Dependencies for testing and development. To let appraisal override them, we
|
7
|
+
# do NOT put them in group :test,:development -- which anyway doesn't make a
|
8
|
+
# lot of sense in a gem Gemfile anyway, there is no "production" in a gem Gemfile.
|
9
|
+
#
|
10
|
+
# We also have these development dependencies here in the Gemfile instead of the
|
11
|
+
# gemspec so appraisal can override them from our Appraisal file.
|
12
|
+
|
13
|
+
gem 'combustion', '~> 1.1'
|
14
|
+
|
15
|
+
# all of rails is NOT a dependency, just activerecord.
|
16
|
+
# But we use it for integration testing with combustion. Hmm, a bit annoying
|
17
|
+
# that now our other tests can't be sure they're depending, this might not
|
18
|
+
# be the way to do it.
|
19
|
+
gem 'rails'
|
20
|
+
|
21
|
+
gem "pg"
|
22
|
+
gem "rspec-rails", "~> 6.0"
|
23
|
+
gem "simple_form", ">= 4.0"
|
24
|
+
gem 'cocoon', ">= 1.2"
|
25
|
+
gem 'jquery-rails'
|
26
|
+
|
27
|
+
# Even though we don't use coffee-script, when running specs, some part of rails
|
28
|
+
# or other part of our stack is still insisting on requiring it, for reasons we
|
29
|
+
# don't understand, so we need to depend on it.
|
30
|
+
gem "coffee-rails"
|
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
|
+
|
39
|
+
gem 'capybara', "~> 3.0"
|
40
|
+
gem 'webdrivers', '~> 5.0'
|
41
|
+
gem "selenium-webdriver"
|
41
42
|
|
42
43
|
gem "byebug"
|
44
|
+
|
45
|
+
|