activerecord-nested_attribute_destruction 0.1.0 → 0.1.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/CHANGELOG.md +4 -0
- data/Gemfile.lock +2 -2
- data/README.md +40 -2
- data/lib/nested_attribute_destruction/monitor.rb +4 -2
- data/lib/nested_attribute_destruction/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ceaff9a731ffccd9d26e122b49d69936b6d4401c05f159740a455494dfecb9bf
|
4
|
+
data.tar.gz: 32cb47ef8c9efa02f89141952cf914bad2ce72b39408630283bca21ea3011429
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3fcb0ff80ca9b0e6af312ddb125f463e01a289eb9c8429f077a8540c96004c6d49d475bbff8b3b53a6a067e925f41dd5a231a54a61879a02efea2c3b64a7fe60
|
7
|
+
data.tar.gz: 4d1faccd22aaacbb84180d0100289dad76208684c9e06c769f531783ce921f929dd8968a13861d2f35203bec68f8203a86011a357baceea9b6ee71e6efbc3f72
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
activerecord-nested_attribute_destruction (0.1.
|
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.
|
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
|
+
[](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
|
93
|
-
|
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
|
|
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.
|
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:
|
11
|
+
date: 2022-01-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|