support_table_data 1.3.0 → 1.4.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 23cac76e97a2a99d97d7c5fba3c79c43d1a3391e1b035eea2e52cb223f211c5b
4
- data.tar.gz: d73302038185694e8dd55f55c291f71fbd20f792e02d2a8eff6f1c2bee92f37f
3
+ metadata.gz: 57189f00e55af0f6d3476edbe8921bfb7ba341fa9a1c6e51eb0674e66327bd12
4
+ data.tar.gz: f80d9a8f7ce4877aec13c5f0151ddc017bbcb94ea4b85b2c404b23161d11aaf8
5
5
  SHA512:
6
- metadata.gz: c4c317e39dd17d1bba310af7067e534a9c8fb63b85625d6d6eef36dc06d8de4d2427cdc08b450721ee99fb027cf4b76f5e7a51fdf0ef488a90bf6a29b0b15b36
7
- data.tar.gz: 7510b5ec898006085aa9686d179ff0a50c6a87d74c26db63c82fbc284e46357111169cfe60aecacf27b8db4c3881ce2c3024acf890ead31d959eaa5a860ff0a8
6
+ metadata.gz: df96d9b761bb03c2ddc9bc915bc5441c24f8bf06e20f53fb2d962ae74c19f6828f84f3b4c3f5c1fe6766bceed05c4e64ec6ae458c64c9e6bf549855b4a492222
7
+ data.tar.gz: 820ebdea69220e6a03c5b0966138285af9c7e3181c73532917d074c392cc0a708d5bb4c67d0d11f937ef0ffd81e828f226f64aa0a632ec7475578d8edc2a53d6
data/CHANGELOG.md CHANGED
@@ -4,6 +4,22 @@ All 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
+ ## 1.4.0
8
+
9
+ ### Fixed
10
+
11
+ - Honor single table inheritance class when creating new records in the database. This fixes issues where validations and callbacks on subclasses could be skipped when creating new records.
12
+
13
+ ### Removed
14
+
15
+ - Removed support for ActiveRecord versions prior to 6.1.
16
+
17
+ ## 1.3.1
18
+
19
+ ### Added
20
+
21
+ - Added support for autosave associations. Data in autosave associations will be persisted when the support table is synced if it was changed by the support table data.
22
+
7
23
  ## 1.3.0
8
24
 
9
25
  ### Added
data/README.md CHANGED
@@ -232,7 +232,7 @@ class Thing < ApplicationRecord
232
232
  add_support_table_data "things.yml"
233
233
 
234
234
  has_many :thing_widgets
235
- has_many :widgets, through: :thing_widgets
235
+ has_many :widgets, through: :thing_widgets, autosave: true
236
236
 
237
237
  # The Thing model is responsible for loading the thing_widgets join table by means of the widget_names=
238
238
  # setter method. We need to define the depdenency to ensure widgets are loaded first.
@@ -244,6 +244,8 @@ class Thing < ApplicationRecord
244
244
  end
245
245
  ```
246
246
 
247
+ If you use a method to set a `has_many` association on your model, you **must** set the `autosave` option to `true` on the association (see the above example). This will ensure the association records are always saved even if there were no changes to the parent record.
248
+
247
249
  You need to call `SupportTableData.sync_all!` when deploying your application. This gem includes a rake task `support_table_data:sync` that is suitable for hooking into deploy scripts. An easy way to hook it into a Rails application is by enhancing the `db:migrate` task so that the sync task runs immediately after database migrations are run. You can do this by adding code to a Rakefile in your application's `lib/tasks` directory:
248
250
 
249
251
  ```ruby
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.3.0
1
+ 1.4.0
@@ -49,14 +49,16 @@ module SupportTableData
49
49
  attributes&.each do |name, value|
50
50
  record.send(:"#{name}=", value) if record.respond_to?(:"#{name}=", true)
51
51
  end
52
- if record.changed?
52
+ if support_table_record_changed?(record)
53
53
  changes << record.changes
54
54
  record.save!
55
55
  end
56
56
  end
57
57
 
58
58
  canonical_data.each_value do |attributes|
59
- record = new
59
+ class_name = attributes[inheritance_column]
60
+ klass = class_name ? sti_class_for(class_name) : self
61
+ record = klass.new
60
62
  attributes.each do |name, value|
61
63
  record.send(:"#{name}=", value) if record.respond_to?(:"#{name}=", true)
62
64
  end
@@ -323,6 +325,20 @@ module SupportTableData
323
325
 
324
326
  data
325
327
  end
328
+
329
+ def support_table_record_changed?(record, seen = Set.new)
330
+ return true if record.changed?
331
+
332
+ seen << self
333
+ record.class.reflect_on_all_associations.detect do |reflection|
334
+ next false if reflection.belongs_to?
335
+ next false unless reflection.options[:autosave]
336
+
337
+ record.association(reflection.name).target.any? do |child|
338
+ support_table_record_changed?(child, seen) unless seen.include?(child)
339
+ end
340
+ end
341
+ end
326
342
  end
327
343
 
328
344
  class << self
@@ -35,7 +35,7 @@ Gem::Specification.new do |spec|
35
35
 
36
36
  spec.required_ruby_version = ">= 2.5"
37
37
 
38
- spec.add_dependency "activerecord"
38
+ spec.add_dependency "activerecord", ">= 6"
39
39
 
40
40
  spec.add_development_dependency "bundler"
41
41
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: support_table_data
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Durand
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-01-30 00:00:00.000000000 Z
11
+ date: 2025-05-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: '6'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '0'
26
+ version: '6'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement