activerecord-nested_attribute_destruction 0.1.0 → 0.1.1

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: af843c559bcd2739db207cfb8f4ce7976d5fccb8b003af5693f1f875c2926cfd
4
- data.tar.gz: bf2f1ca17b5b9af2114c360fbad1311f976a064a6d4521894ed8666f8a03a456
3
+ metadata.gz: ceaff9a731ffccd9d26e122b49d69936b6d4401c05f159740a455494dfecb9bf
4
+ data.tar.gz: 32cb47ef8c9efa02f89141952cf914bad2ce72b39408630283bca21ea3011429
5
5
  SHA512:
6
- metadata.gz: a5197efe66c61cf0c9d1cfbe4bbc31c63d7250e16bf3849bfc884825739bc9623b1558aba9465ad7575b96aa5333a1abcfad56939982d408503b3c39c8fd6d76
7
- data.tar.gz: 599de273a9aefa457d6370696f8f8a24539d109f84642787b8f9abd688b02585ebfceffda744def5baa0cf1efa25c126cb336901f23a9ec27abf6311e767605a
6
+ metadata.gz: 3fcb0ff80ca9b0e6af312ddb125f463e01a289eb9c8429f077a8540c96004c6d49d475bbff8b3b53a6a067e925f41dd5a231a54a61879a02efea2c3b64a7fe60
7
+ data.tar.gz: 4d1faccd22aaacbb84180d0100289dad76208684c9e06c769f531783ce921f929dd8968a13861d2f35203bec68f8203a86011a357baceea9b6ee71e6efbc3f72
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.1.1] - 2022-01-17
4
+
5
+ Fixed bug where the monitor might not have been created yet when it is accessed.
6
+
3
7
  ## [0.1.0] - 2021-12-22
4
8
 
5
9
  - Initial release
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- activerecord-nested_attribute_destruction (0.1.0)
4
+ activerecord-nested_attribute_destruction (0.1.1)
5
5
  activerecord (>= 5.2.0)
6
6
 
7
7
  GEM
@@ -181,4 +181,4 @@ DEPENDENCIES
181
181
  sqlite3 (~> 1.4.2)
182
182
 
183
183
  BUNDLED WITH
184
- 2.3.2
184
+ 2.3.4
data/README.md CHANGED
@@ -1,5 +1,28 @@
1
1
  # activerecord-nested\_attribute\_destruction
2
2
 
3
+ Build status for all matrix combinations listed in [compatibility](#compatibility)
4
+
5
+ [![CircleCI](https://circleci.com/gh/brandoncc/activerecord-nested_attribute_destruction.svg?style=svg)](https://circleci.com/gh/brandoncc/activerecord-nested_attribute_destruction)
6
+
7
+ ## TL;DR
8
+
9
+ ```ruby
10
+ class Harbor
11
+ has_many :ships
12
+
13
+ accepts_nested_attributes_for :ships, allow_destroy: true
14
+ end
15
+
16
+ harbor.ships_attributes = [harbor.ships.first.attributes.merge('_destroy': true)]
17
+ harbor.save!
18
+
19
+ harbor.ships_destroyed_during_save? # true
20
+ ```
21
+
22
+ See that last line of code? That is what this gem adds :smiley:
23
+
24
+ ## Description
25
+
3
26
  Active Record offers introspection of saved changes for almost everything you
4
27
  could want. The one thing I have repeatedly found myself wishing for was a way
5
28
  to know if a nested attribute was destroyed during save via
@@ -89,8 +112,12 @@ To see more examples, take a look at [the tests](https://github.com/brandoncc/ac
89
112
 
90
113
  ## Compatibility
91
114
 
92
- This gem is built and its tests are run for the following ruby/active record
93
- combinations:
115
+ This gem should be compatible with all versions of Ruby 2.3 and higher. It
116
+ should be compatible with Active Record versions 5.2 and up.
117
+
118
+ Because of rubocop dependencies and keyword arguments changes in Ruby 3.0 which
119
+ affected the database setup code used in the test suite, it is only tested
120
+ against the matrices displayed below.
94
121
 
95
122
  ### Sorted by Active Record version
96
123
 
@@ -126,6 +153,17 @@ combinations:
126
153
  | 3.0 | 6.1 |
127
154
  | 3.0 | 7.0 |
128
155
 
156
+ ### Specific requirements
157
+
158
+ #### Ruby
159
+
160
+ The safe navigation operator, introduced in Ruby 2.3, is used.
161
+
162
+ #### Active Record
163
+
164
+ The [API changes](https://www.fastruby.io/blog/rails/upgrades/active-record-5-1-api-changes.html)
165
+ in Active Record 5.2 are necessary for the core functionality of the gem.
166
+
129
167
  ## Development
130
168
 
131
169
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -19,7 +19,6 @@ module NestedAttributeDestruction
19
19
 
20
20
  def define_predicate(klass, assoc_name)
21
21
  klass.define_method("#{assoc_name}_destroyed_during_save?") do
22
- @nested_attribute_destruction_monitor ||= NestedAttributeDestruction::Monitor.new
23
22
  @nested_attribute_destruction_monitor.send(:destroyed_during_save?, assoc_name.to_sym)
24
23
  end
25
24
  end
@@ -27,8 +26,11 @@ module NestedAttributeDestruction
27
26
  private
28
27
 
29
28
  def define_callbacks(klass)
29
+ klass.after_initialize do
30
+ @nested_attribute_destruction_monitor = NestedAttributeDestruction::Monitor.new
31
+ end
32
+
30
33
  klass.before_update do |obj|
31
- @nested_attribute_destruction_monitor ||= NestedAttributeDestruction::Monitor.new
32
34
  @nested_attribute_destruction_monitor.send(:store_attributes_marked_for_destruction, obj)
33
35
  end
34
36
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module NestedAttributeDestruction
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.1"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord-nested_attribute_destruction
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brandon Conway
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-12-24 00:00:00.000000000 Z
11
+ date: 2022-01-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord