support_table_data 1.3.0 → 1.3.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 23cac76e97a2a99d97d7c5fba3c79c43d1a3391e1b035eea2e52cb223f211c5b
4
- data.tar.gz: d73302038185694e8dd55f55c291f71fbd20f792e02d2a8eff6f1c2bee92f37f
3
+ metadata.gz: 246d91c74bc3b4a5afc75899786785139dc4b9bde91f0af778af63d1f374306b
4
+ data.tar.gz: c7290495c52166a9068806ffce68fbb6f161cdebf87546e6eae4a9b9c97deacc
5
5
  SHA512:
6
- metadata.gz: c4c317e39dd17d1bba310af7067e534a9c8fb63b85625d6d6eef36dc06d8de4d2427cdc08b450721ee99fb027cf4b76f5e7a51fdf0ef488a90bf6a29b0b15b36
7
- data.tar.gz: 7510b5ec898006085aa9686d179ff0a50c6a87d74c26db63c82fbc284e46357111169cfe60aecacf27b8db4c3881ce2c3024acf890ead31d959eaa5a860ff0a8
6
+ metadata.gz: f32896080f819f65bfcc59e38801cb69a5a5f98ccc83e6218c587766c5b769aab034b606452909cf9e62a6ea82a23e79150bae42201b73c374489563ed3d1537
7
+ data.tar.gz: ea9af78e06f7439854e7444eab0f96a541a14b7c5918767a464eb56094f415c71b5349b4a2043d12ac1bdebff47d1b8ee485e329cd10112b6c11f11389cbe595
data/CHANGELOG.md CHANGED
@@ -4,6 +4,12 @@ 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.3.1
8
+
9
+ ### Added
10
+
11
+ - 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.
12
+
7
13
  ## 1.3.0
8
14
 
9
15
  ### 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.3.1
@@ -49,7 +49,7 @@ 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
@@ -323,6 +323,20 @@ module SupportTableData
323
323
 
324
324
  data
325
325
  end
326
+
327
+ def support_table_record_changed?(record, seen = Set.new)
328
+ return true if record.changed?
329
+
330
+ seen << self
331
+ record.class.reflect_on_all_associations.detect do |reflection|
332
+ next false if reflection.belongs_to?
333
+ next false unless reflection.options[:autosave]
334
+
335
+ record.association(reflection.name).target.any? do |child|
336
+ support_table_record_changed?(child, seen) unless seen.include?(child)
337
+ end
338
+ end
339
+ end
326
340
  end
327
341
 
328
342
  class << self
metadata CHANGED
@@ -1,7 +1,7 @@
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.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Durand