attr_json 1.4.0 → 1.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +10 -3
- data/.github/workflows/future_rails_ci.yml +2 -2
- data/Appraisals +9 -11
- data/CHANGELOG.md +15 -1
- data/Gemfile +9 -2
- data/README.md +5 -5
- data/attr_json.gemspec +0 -1
- data/gemfiles/rails_5_0.gemfile +1 -0
- data/gemfiles/rails_5_1.gemfile +1 -0
- data/gemfiles/rails_5_2.gemfile +1 -0
- data/gemfiles/rails_6_0.gemfile +1 -0
- data/gemfiles/rails_6_1.gemfile +1 -0
- data/gemfiles/rails_7_0.gemfile +1 -1
- data/gemfiles/rails_edge.gemfile +2 -2
- data/lib/attr_json/model.rb +41 -25
- data/lib/attr_json/record/dirty.rb +7 -1
- data/lib/attr_json/version.rb +1 -1
- metadata +3 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
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
|
data/.github/workflows/ci.yml
CHANGED
@@ -54,15 +54,22 @@ jobs:
|
|
54
54
|
ruby: 2.7
|
55
55
|
|
56
56
|
- gemfile: rails_6_1
|
57
|
-
ruby: 3.0
|
57
|
+
ruby: '3.0'
|
58
58
|
|
59
59
|
- gemfile: rails_7_0
|
60
|
-
ruby: 3.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
|
+
|
61
68
|
|
62
69
|
name: ${{ matrix.gemfile }}, ruby ${{ matrix.ruby }}
|
63
70
|
|
64
71
|
steps:
|
65
|
-
- uses: actions/checkout@
|
72
|
+
- uses: actions/checkout@v3
|
66
73
|
|
67
74
|
- name: Set up Ruby
|
68
75
|
uses: ruby/setup-ruby@v1
|
@@ -45,12 +45,12 @@ jobs:
|
|
45
45
|
include:
|
46
46
|
|
47
47
|
- gemfile: rails_edge
|
48
|
-
ruby:
|
48
|
+
ruby: '3.1'
|
49
49
|
|
50
50
|
name: ${{ matrix.gemfile }}, ruby ${{ matrix.ruby }}
|
51
51
|
|
52
52
|
steps:
|
53
|
-
- uses: actions/checkout@
|
53
|
+
- uses: actions/checkout@v3
|
54
54
|
|
55
55
|
- name: Set up Ruby
|
56
56
|
uses: ruby/setup-ruby@v1
|
data/Appraisals
CHANGED
@@ -37,6 +37,11 @@ appraise "rails-6-1" do
|
|
37
37
|
|
38
38
|
gem "rails", "~> 6.1.0"
|
39
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"
|
40
45
|
end
|
41
46
|
|
42
47
|
appraise "rails-7-0" do
|
@@ -44,21 +49,14 @@ appraise "rails-7-0" do
|
|
44
49
|
|
45
50
|
gem "rails", "~> 7.0.0"
|
46
51
|
gem "pg", "~> 1.0"
|
47
|
-
|
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"
|
52
52
|
end
|
53
53
|
|
54
54
|
appraise "rails-edge" do
|
55
|
-
|
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"
|
56
59
|
|
57
60
|
gem "rails", git: "https://github.com/rails/rails.git", branch: "main"
|
58
61
|
gem "pg", "~> 1.0"
|
59
|
-
|
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"
|
64
62
|
end
|
data/CHANGELOG.md
CHANGED
@@ -4,10 +4,24 @@ 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.
|
7
|
+
## [Unreleased](https://github.com/jrochkind/attr_json/compare/v1.4.1...HEAD)
|
8
8
|
|
9
9
|
|
10
|
+
## [1.5.0](https://github.com/jrochkind/attr_json/compare/v1.4.1...v1.5.0)
|
10
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
|
11
25
|
|
12
26
|
## [1.4.0](https://github.com/jrochkind/attr_json/compare/v1.3.0...v1.4.0)
|
13
27
|
|
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", "~>
|
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,15 @@ 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', '~>
|
40
|
+
gem 'webdrivers', '~> 5.0'
|
34
41
|
gem "selenium-webdriver"
|
35
42
|
|
36
43
|
gem "byebug"
|
data/README.md
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
[![Gem Version](https://badge.fury.io/rb/attr_json.svg)](https://badge.fury.io/rb/attr_json)
|
5
5
|
|
6
6
|
|
7
|
-
ActiveRecord attributes stored serialized in a json column, super smooth. For Rails 5.0 through
|
7
|
+
ActiveRecord attributes stored serialized in a json column, super smooth. For Rails 5.0 through 7.0. Ruby 2.4+.
|
8
8
|
|
9
9
|
Typed and cast like Active Record. Supporting [nested models](#nested), [dirty tracking](#dirty), some [querying](#querying) (with postgres [jsonb](https://www.postgresql.org/docs/9.5/static/datatype-json.html) contains), and [working smoothy with form builders](#forms).
|
10
10
|
|
@@ -478,15 +478,15 @@ to prevent overwriting other updates from processes.
|
|
478
478
|
|
479
479
|
## State of Code, and To Be Done
|
480
480
|
|
481
|
-
This code is solid and stable and is being used in production by at least a handful of people, including the primary maintainer, jrochkind.
|
481
|
+
This code is solid and stable and is being used in production by at least a handful of people, including the primary maintainer, jrochkind.
|
482
482
|
|
483
|
-
The project is currently getting very little maintainance -- and is still working reliably through Rails releases. It is tested on edge rails and ruby (and has needed very few if any changes with subsequent releases), and I endeavor to keep it working as Rails keeps releasing.
|
483
|
+
The project is currently getting very little maintainance -- and is still working reliably through Rails releases. It is tested on edge rails and ruby (and has needed very few if any changes with subsequent releases), and I endeavor to keep it working as Rails keeps releasing.
|
484
484
|
|
485
|
-
In order to keep the low-maintenace scenario sustainable, I am *very* cautious accepting new features, especially if they increase code complexity at all. Even if you have a working PR, I may be reluctant to accept it. I'm prioritizing sustainability and stability over new features, and so far this is working out well. However, discussion is always welcome! Especially when paired with code (failing tests for the bugfix or feature you want are super helpful on their own!).
|
485
|
+
In order to keep the low-maintenace scenario sustainable, I am *very* cautious accepting new features, especially if they increase code complexity at all. Even if you have a working PR, I may be reluctant to accept it. I'm prioritizing sustainability and stability over new features, and so far this is working out well. However, discussion is always welcome! Especially when paired with code (failing tests for the bugfix or feature you want are super helpful on their own!).
|
486
486
|
|
487
487
|
We are committed to [semantic versioning](https://semver.org/) and will endeavor to release no backwards breaking changes without a major version. We are also serious about minimizing backwards incompat releases altogether (ie minimiing major version releases).
|
488
488
|
|
489
|
-
Feedback of any kind of _very welcome_, please feel free to use the issue tracker. It is hard to get a sense of how many people are actually using this, which is helpful both for my own sense of reward and for anyone to get a sense of the size of the userbase -- feel free to say hi and let us know how you are using it!
|
489
|
+
Feedback of any kind of _very welcome_, please feel free to use the issue tracker. It is hard to get a sense of how many people are actually using this, which is helpful both for my own sense of reward and for anyone to get a sense of the size of the userbase -- feel free to say hi and let us know how you are using it!
|
490
490
|
|
491
491
|
Except for the jsonb_contains stuff using postgres jsonb contains operator, I don't believe any postgres-specific features are used. It ought to work with MySQL, testing and feedback welcome. (Or a PR to test on MySQL?). My own interest is postgres.
|
492
492
|
|
data/attr_json.gemspec
CHANGED
@@ -51,7 +51,6 @@ attributes use as much of the existing ActiveRecord architecture as we can.}
|
|
51
51
|
spec.add_development_dependency "bundler"
|
52
52
|
spec.add_development_dependency "rake", ">= 10.0"
|
53
53
|
spec.add_development_dependency "rspec", "~> 3.7"
|
54
|
-
spec.add_development_dependency "database_cleaner", "~> 1.5"
|
55
54
|
spec.add_development_dependency "yard-activesupport-concern"
|
56
55
|
spec.add_development_dependency "appraisal", "~> 2.2"
|
57
56
|
|
data/gemfiles/rails_5_0.gemfile
CHANGED
data/gemfiles/rails_5_1.gemfile
CHANGED
data/gemfiles/rails_5_2.gemfile
CHANGED
data/gemfiles/rails_6_0.gemfile
CHANGED
data/gemfiles/rails_6_1.gemfile
CHANGED
data/gemfiles/rails_7_0.gemfile
CHANGED
@@ -10,10 +10,10 @@ gem "simple_form", ">= 4.0"
|
|
10
10
|
gem "cocoon", ">= 1.2"
|
11
11
|
gem "jquery-rails"
|
12
12
|
gem "coffee-rails"
|
13
|
+
gem "sprockets-rails"
|
13
14
|
gem "capybara", "~> 3.0"
|
14
15
|
gem "webdrivers", "~> 4.0"
|
15
16
|
gem "selenium-webdriver"
|
16
17
|
gem "byebug"
|
17
|
-
gem "sprockets-rails"
|
18
18
|
|
19
19
|
gemspec path: "../"
|
data/gemfiles/rails_edge.gemfile
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
source "https://rubygems.org"
|
4
4
|
|
5
|
-
gem "combustion", "~> 1.0"
|
5
|
+
gem "combustion", "~> 1.0", github: "pat/combustion"
|
6
6
|
gem "rails", git: "https://github.com/rails/rails.git", branch: "main"
|
7
7
|
gem "pg", "~> 1.0"
|
8
8
|
gem "rspec-rails", "~> 4.0"
|
@@ -10,10 +10,10 @@ gem "simple_form", ">= 4.0"
|
|
10
10
|
gem "cocoon", ">= 1.2"
|
11
11
|
gem "jquery-rails"
|
12
12
|
gem "coffee-rails"
|
13
|
+
gem "sprockets-rails"
|
13
14
|
gem "capybara", "~> 3.0"
|
14
15
|
gem "webdrivers", "~> 4.0"
|
15
16
|
gem "selenium-webdriver"
|
16
17
|
gem "byebug"
|
17
|
-
gem "sprockets-rails"
|
18
18
|
|
19
19
|
gemspec path: "../"
|
data/lib/attr_json/model.rb
CHANGED
@@ -135,6 +135,17 @@ module AttrJson
|
|
135
135
|
@serialization_coder ||= AttrJson::SerializationCoderFromType.new(to_type)
|
136
136
|
end
|
137
137
|
|
138
|
+
# like the ActiveModel::Attributes method
|
139
|
+
def attribute_names
|
140
|
+
attr_json_registry.attribute_names
|
141
|
+
end
|
142
|
+
|
143
|
+
# like the ActiveModel::Attributes method, hash with name keys, and ActiveModel::Type values
|
144
|
+
def attribute_types
|
145
|
+
attribute_names.collect { |name| [name.to_s, attr_json_registry.type_for_attribute(name)]}.to_h
|
146
|
+
end
|
147
|
+
|
148
|
+
|
138
149
|
# Type can be an instance of an ActiveModel::Type::Value subclass, or a symbol that will
|
139
150
|
# be looked up in `ActiveModel::Type.lookup`
|
140
151
|
#
|
@@ -177,27 +188,6 @@ module AttrJson
|
|
177
188
|
end
|
178
189
|
end
|
179
190
|
|
180
|
-
# This should kind of be considered 'protected', but the semantics
|
181
|
-
# of how we want to call it don't give us a visibility modifier that works.
|
182
|
-
# Prob means refactoring called for. TODO?
|
183
|
-
def fill_in_defaults(hash)
|
184
|
-
# Only if we need to mutate it to add defaults, we'll dup it first. deep_dup not neccesary
|
185
|
-
# since we're only modifying top-level here.
|
186
|
-
duped = false
|
187
|
-
attr_json_registry.definitions.each do |definition|
|
188
|
-
if definition.has_default? && ! (hash.has_key?(definition.store_key.to_s) || hash.has_key?(definition.store_key.to_sym))
|
189
|
-
unless duped
|
190
|
-
hash = hash.dup
|
191
|
-
duped = true
|
192
|
-
end
|
193
|
-
|
194
|
-
hash[definition.store_key] = definition.provide_default!
|
195
|
-
end
|
196
|
-
end
|
197
|
-
|
198
|
-
hash
|
199
|
-
end
|
200
|
-
|
201
191
|
private
|
202
192
|
|
203
193
|
# Define an anonymous module and include it, so can still be easily
|
@@ -213,11 +203,15 @@ module AttrJson
|
|
213
203
|
end
|
214
204
|
|
215
205
|
def initialize(attributes = {})
|
216
|
-
|
217
|
-
|
218
|
-
|
206
|
+
super
|
207
|
+
|
208
|
+
fill_in_defaults!
|
209
|
+
end
|
219
210
|
|
220
|
-
|
211
|
+
# inspired by https://github.com/rails/rails/blob/8015c2c2cf5c8718449677570f372ceb01318a32/activemodel/lib/active_model/attributes.rb
|
212
|
+
def initialize_dup(other) # :nodoc:
|
213
|
+
@attributes = @attributes.deep_dup
|
214
|
+
super
|
221
215
|
end
|
222
216
|
|
223
217
|
def attributes
|
@@ -255,6 +249,11 @@ module AttrJson
|
|
255
249
|
self.class.attr_json_registry.has_attribute?(str)
|
256
250
|
end
|
257
251
|
|
252
|
+
# like the ActiveModel::Attributes method
|
253
|
+
def attribute_names
|
254
|
+
self.class.attribute_names
|
255
|
+
end
|
256
|
+
|
258
257
|
# Override from ActiveModel::Serialization to #serialize
|
259
258
|
# by type to make sure any values set directly on hash still
|
260
259
|
# get properly type-serialized.
|
@@ -301,8 +300,25 @@ module AttrJson
|
|
301
300
|
false
|
302
301
|
end
|
303
302
|
|
303
|
+
# like ActiveModel::Attributes at
|
304
|
+
# https://github.com/rails/rails/blob/8015c2c2cf5c8718449677570f372ceb01318a32/activemodel/lib/active_model/attributes.rb#L120
|
305
|
+
#
|
306
|
+
# is not a full deep freeze
|
307
|
+
def freeze
|
308
|
+
attributes.freeze unless frozen?
|
309
|
+
super
|
310
|
+
end
|
311
|
+
|
304
312
|
private
|
305
313
|
|
314
|
+
def fill_in_defaults!
|
315
|
+
self.class.attr_json_registry.definitions.each do |definition|
|
316
|
+
if definition.has_default? && !attributes.has_key?(definition.name.to_s)
|
317
|
+
self.send("#{definition.name.to_s}=", definition.provide_default!)
|
318
|
+
end
|
319
|
+
end
|
320
|
+
end
|
321
|
+
|
306
322
|
def _attr_json_write(key, value)
|
307
323
|
if attribute_def = self.class.attr_json_registry[key.to_sym]
|
308
324
|
attributes[key.to_s] = attribute_def.cast(value)
|
@@ -270,7 +270,13 @@ module AttrJson
|
|
270
270
|
# find it from currently declared attributes.
|
271
271
|
# https://github.com/rails/rails/blob/6aa5cf03ea8232180ffbbae4c130b051f813c670/activemodel/lib/active_model/attribute_methods.rb#L463-L468
|
272
272
|
def matched_attribute_method(method_name)
|
273
|
-
|
273
|
+
if self.class.respond_to?(:attribute_method_patterns_matching, true)
|
274
|
+
# Rails 7.1+
|
275
|
+
matches = self.class.send(:attribute_method_patterns_matching, method_name)
|
276
|
+
else
|
277
|
+
matches = self.class.send(:attribute_method_matchers_matching, method_name)
|
278
|
+
end
|
279
|
+
|
274
280
|
matches.detect do |match|
|
275
281
|
registry.has_attribute?(match.attr_name)
|
276
282
|
end
|
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: 1.
|
4
|
+
version: 1.5.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:
|
11
|
+
date: 2023-01-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -72,20 +72,6 @@ dependencies:
|
|
72
72
|
- - "~>"
|
73
73
|
- !ruby/object:Gem::Version
|
74
74
|
version: '3.7'
|
75
|
-
- !ruby/object:Gem::Dependency
|
76
|
-
name: database_cleaner
|
77
|
-
requirement: !ruby/object:Gem::Requirement
|
78
|
-
requirements:
|
79
|
-
- - "~>"
|
80
|
-
- !ruby/object:Gem::Version
|
81
|
-
version: '1.5'
|
82
|
-
type: :development
|
83
|
-
prerelease: false
|
84
|
-
version_requirements: !ruby/object:Gem::Requirement
|
85
|
-
requirements:
|
86
|
-
- - "~>"
|
87
|
-
- !ruby/object:Gem::Version
|
88
|
-
version: '1.5'
|
89
75
|
- !ruby/object:Gem::Dependency
|
90
76
|
name: yard-activesupport-concern
|
91
77
|
requirement: !ruby/object:Gem::Requirement
|
@@ -225,7 +211,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
225
211
|
- !ruby/object:Gem::Version
|
226
212
|
version: '0'
|
227
213
|
requirements: []
|
228
|
-
rubygems_version: 3.
|
214
|
+
rubygems_version: 3.2.33
|
229
215
|
signing_key:
|
230
216
|
specification_version: 4
|
231
217
|
summary: ActiveRecord attributes stored serialized in a json column, super smooth.
|