attr_json 1.4.1 → 1.5.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: 3f2658693e8b0c4d99e412e33c8d2ef67a70bb71302f0d3d079326bef2380c44
4
- data.tar.gz: 6acbf7ca9e743a2a22550731baf495306bc087fd3787c02ea19435b94f96a85d
3
+ metadata.gz: 3cd2566fed014325bee56f5c062080d3c929a790dbb3b287e92b086c2fa3180f
4
+ data.tar.gz: ffa8e7b471dce27a2708b12e6a2bf27edb5b20d1345656ca026ecc4b263a01a7
5
5
  SHA512:
6
- metadata.gz: 9a3cf5a739623ba998162b0072b351a2ae07316691dc013c2f88820dc36d5119833d64bc89335379dbd636f65fcf4253f818649f57538c753b0a5d98fc7c5b6c
7
- data.tar.gz: 79a977eb57509ad7035bb5d20e6212568d51b8062de11d536bbeae58acab8bc8db48eba181adeecff97286fa59042b6eb143359b41a7c65d73955fb18c2edc75
6
+ metadata.gz: f8db6d4211a2dd9f4b9d8a5482b723597958082617e139157c325e8e3b9dddf15216d21bd56daece5d5b3674acdc8e099a22998ad452473a4bf0834774b7a21f
7
+ data.tar.gz: 13e2cd5b4b10f67f4ecfc1be8732c6a33a7f7a7fdb561b6d8f4f89ae39c74e4b0b153ae10fdf5d650a239534f5b28cd33750aaff90009eeec8877677e765a935
@@ -62,6 +62,10 @@ jobs:
62
62
  - gemfile: rails_7_0
63
63
  ruby: 3.1
64
64
 
65
+ - gemfile: rails_7_0
66
+ ruby: 3.2
67
+
68
+
65
69
  name: ${{ matrix.gemfile }}, ruby ${{ matrix.ruby }}
66
70
 
67
71
  steps:
@@ -45,12 +45,12 @@ jobs:
45
45
  include:
46
46
 
47
47
  - gemfile: rails_edge
48
- ruby: '3.0'
48
+ ruby: '3.1'
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/CHANGELOG.md CHANGED
@@ -4,9 +4,19 @@ 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)
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)
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
+
10
20
  ## [1.4.1](https://github.com/jrochkind/attr_json/compare/v1.4.0...v1.4.1)
11
21
 
12
22
  ### Fixed
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'
@@ -37,7 +37,7 @@ gem "sprockets-rails"
37
37
 
38
38
 
39
39
  gem 'capybara', "~> 3.0"
40
- gem 'webdrivers', '~> 4.0'
40
+ gem 'webdrivers', '~> 5.0'
41
41
  gem "selenium-webdriver"
42
42
 
43
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 6.1. Ruby 2.4+.
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
 
@@ -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
  #
@@ -197,6 +208,12 @@ module AttrJson
197
208
  fill_in_defaults!
198
209
  end
199
210
 
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
215
+ end
216
+
200
217
  def attributes
201
218
  @attributes ||= {}
202
219
  end
@@ -232,6 +249,11 @@ module AttrJson
232
249
  self.class.attr_json_registry.has_attribute?(str)
233
250
  end
234
251
 
252
+ # like the ActiveModel::Attributes method
253
+ def attribute_names
254
+ self.class.attribute_names
255
+ end
256
+
235
257
  # Override from ActiveModel::Serialization to #serialize
236
258
  # by type to make sure any values set directly on hash still
237
259
  # get properly type-serialized.
@@ -278,6 +300,15 @@ module AttrJson
278
300
  false
279
301
  end
280
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
+
281
312
  private
282
313
 
283
314
  def fill_in_defaults!
@@ -1,3 +1,3 @@
1
1
  module AttrJson
2
- VERSION = "1.4.1"
2
+ VERSION = "1.5.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: 1.4.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: 2022-12-20 00:00:00.000000000 Z
11
+ date: 2023-01-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord