attr_json 1.4.0 → 1.4.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/.github/workflows/ci.yml +6 -3
- data/.github/workflows/future_rails_ci.yml +1 -1
- data/Appraisals +9 -11
- data/CHANGELOG.md +4 -0
- data/Gemfile +7 -0
- 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 +10 -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: 3f2658693e8b0c4d99e412e33c8d2ef67a70bb71302f0d3d079326bef2380c44
|
|
4
|
+
data.tar.gz: 6acbf7ca9e743a2a22550731baf495306bc087fd3787c02ea19435b94f96a85d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 9a3cf5a739623ba998162b0072b351a2ae07316691dc013c2f88820dc36d5119833d64bc89335379dbd636f65fcf4253f818649f57538c753b0a5d98fc7c5b6c
|
|
7
|
+
data.tar.gz: 79a977eb57509ad7035bb5d20e6212568d51b8062de11d536bbeae58acab8bc8db48eba181adeecff97286fa59042b6eb143359b41a7c65d73955fb18c2edc75
|
data/.github/workflows/ci.yml
CHANGED
|
@@ -54,15 +54,18 @@ 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
|
|
61
64
|
|
|
62
65
|
name: ${{ matrix.gemfile }}, ruby ${{ matrix.ruby }}
|
|
63
66
|
|
|
64
67
|
steps:
|
|
65
|
-
- uses: actions/checkout@
|
|
68
|
+
- uses: actions/checkout@v3
|
|
66
69
|
|
|
67
70
|
- name: Set up Ruby
|
|
68
71
|
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
|
@@ -7,7 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
## [Unreleased](https://github.com/jrochkind/attr_json/compare/v1.4.0...HEAD)
|
|
8
8
|
|
|
9
9
|
|
|
10
|
+
## [1.4.1](https://github.com/jrochkind/attr_json/compare/v1.4.0...v1.4.1)
|
|
10
11
|
|
|
12
|
+
### Fixed
|
|
13
|
+
|
|
14
|
+
* 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
15
|
|
|
12
16
|
## [1.4.0](https://github.com/jrochkind/attr_json/compare/v1.3.0...v1.4.0)
|
|
13
17
|
|
data/Gemfile
CHANGED
|
@@ -29,6 +29,13 @@ 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
40
|
gem 'webdrivers', '~> 4.0'
|
|
34
41
|
gem "selenium-webdriver"
|
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
|
@@ -177,27 +177,6 @@ module AttrJson
|
|
|
177
177
|
end
|
|
178
178
|
end
|
|
179
179
|
|
|
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
180
|
private
|
|
202
181
|
|
|
203
182
|
# Define an anonymous module and include it, so can still be easily
|
|
@@ -213,11 +192,9 @@ module AttrJson
|
|
|
213
192
|
end
|
|
214
193
|
|
|
215
194
|
def initialize(attributes = {})
|
|
216
|
-
|
|
217
|
-
raise ArgumentError, "When assigning attributes, you must pass a hash as an argument."
|
|
218
|
-
end
|
|
195
|
+
super
|
|
219
196
|
|
|
220
|
-
|
|
197
|
+
fill_in_defaults!
|
|
221
198
|
end
|
|
222
199
|
|
|
223
200
|
def attributes
|
|
@@ -303,6 +280,14 @@ module AttrJson
|
|
|
303
280
|
|
|
304
281
|
private
|
|
305
282
|
|
|
283
|
+
def fill_in_defaults!
|
|
284
|
+
self.class.attr_json_registry.definitions.each do |definition|
|
|
285
|
+
if definition.has_default? && !attributes.has_key?(definition.name.to_s)
|
|
286
|
+
self.send("#{definition.name.to_s}=", definition.provide_default!)
|
|
287
|
+
end
|
|
288
|
+
end
|
|
289
|
+
end
|
|
290
|
+
|
|
306
291
|
def _attr_json_write(key, value)
|
|
307
292
|
if attribute_def = self.class.attr_json_registry[key.to_sym]
|
|
308
293
|
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.
|
|
4
|
+
version: 1.4.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:
|
|
11
|
+
date: 2022-12-20 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.
|