replace_with_destroy 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 78cf23a4bee5cbddca1e6b2f8b3a694f8514d4ba8f8ef6d89a9d3f29ed85b72d
4
- data.tar.gz: 69460f5ef330e5f66d5a98325245ae1b38096d9ece8b7a0eb0bb4de6e252e957
3
+ metadata.gz: 9651f245d829790a6af5844f5158b3a8ea96a0c2cfbc99dde6c90447aadbe6cf
4
+ data.tar.gz: 2232361b4341baf823038e34ed8ebe2d1d1c94fec8b0b1f21b7df680bddb2da3
5
5
  SHA512:
6
- metadata.gz: c797a08f7a595a885988a73f2a04fb21db5dffc351480887aa04d5da9c24264683b0ded4f05a7e15b869e58a39b9844a8d3e39a061e5e8fbde71d8223f0df4ad
7
- data.tar.gz: 50a5a6aa7b7d9648639e385546451e6d7b0734846f43a141499d488e113d44a2a582332cf30f02d73e6f18ef3eeeade509537d35f4ad1f4f00f6f5b8b82e13b5
6
+ metadata.gz: a806b8164eff5ca9b5189529715e7646a24381268656445241ff41997a57152e4a86c89ed6dc2bd402631651fe35eda64db40cc8ced0ecabab30163db99e1ed9
7
+ data.tar.gz: 33065c4c9e87a5d2344d321f92e18e04e06e70e68aae49d0c3178d692a859f093a20faa708acf64e143a786ed8d166b8cf4a570d9f10c09963f264a985be27d6
data/README.md CHANGED
@@ -1,8 +1,9 @@
1
- # ReplaceWithDestroy
2
- Short description and motivation.
1
+ # Replace with Destroy
2
+ Based on Rails guide [Automatic deletion of join models is direct, no destroy callbacks are triggered.](https://guides.rubyonrails.org/association_basics.html#the-has-many-through-association), which means, Rails will not run destroy callbacks for `has_many` through join model.
3
3
 
4
- ## Usage
5
- How to use my plugin.
4
+ This gem allow you running the destroy callbacks in the join model.
5
+
6
+ This could be useful if you are using [paranoia](https://github.com/rubysherpas/paranoia) and you want change it to un-active instead delete the join model.
6
7
 
7
8
  ## Installation
8
9
  Add this line to your application's Gemfile:
@@ -21,8 +22,50 @@ Or install it yourself as:
21
22
  $ gem install replace_with_destroy
22
23
  ```
23
24
 
24
- ## Contributing
25
- Contribution directions go here.
25
+ ## Usage
26
+ ### *replace_with_destroy* option.
27
+ Pass the option `replace_with_destroy: true` to the `has_many` method.
28
+ ```
29
+ class User < ApplicationRecord
30
+ has_many :bookings
31
+ has_many :rooms, through: :bookings, replace_with_destroy: true
32
+ end
33
+
34
+ class Booking < ApplicationRecord
35
+ belongs_to :user
36
+ belongs_to :room
37
+
38
+ after_destroy :my_custom_method
39
+
40
+ def my_custom_method
41
+ # do whatever you want here ...
42
+ end
43
+ end
44
+
45
+ class Room < ApplicationRecord
46
+ ...
47
+ end
48
+ ```
49
+
50
+ Then, given the User `user` with rooms `[1,2,3]` you can change his `rooms` and this automatically call Booking destroy callbacks.
51
+ ```
52
+ # given a User with rooms
53
+ > user.room_ids
54
+ [1, 2, 3]
55
+
56
+ # you can change his rooms
57
+ user.room_ids = [3, 4, 5]
58
+ # this add the rooms 4 and 5 and remove the rooms 1 and 2
59
+ # my_custom_method will be executed for rooms 1 and 2 when being removed
60
+ ```
61
+
62
+ ### global *replace_with_destroy* option.
63
+ You can add this behavior for all `has_many` methods without need to pass it as option.
64
+
65
+ To do that, create an initializer, for example `config/initializers/replace_with_destroy.rb`, and put the following code
66
+ ```
67
+ ReplaceWithDestroy::ALL = true
68
+ ```
26
69
 
27
70
  ## License
28
71
  The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile CHANGED
@@ -14,11 +14,6 @@ RDoc::Task.new(:rdoc) do |rdoc|
14
14
  rdoc.rdoc_files.include('lib/**/*.rb')
15
15
  end
16
16
 
17
-
18
-
19
-
20
-
21
-
22
17
  require 'bundler/gem_tasks'
23
18
 
24
19
  require 'rake/testtask'
@@ -27,9 +27,3 @@ module ActiveRecord
27
27
  end
28
28
 
29
29
  ActiveRecord::Associations::Builder::Association::VALID_OPTIONS << :replace_with_destroy
30
-
31
- p "+++++++++++++++++++++++++++++++++++++++++++++++++++++"
32
- p "+++++++++++++++++++++++++++++++++++++++++++++++++++++"
33
- p "+++++++++++++++++++++++++++++++++++++++++++++++++++++"
34
- p "+++++++++++++++++++++++++++++++++++++++++++++++++++++"
35
- p "Running Replace with destroy"
@@ -1,3 +1,3 @@
1
1
  module ReplaceWithDestroy
2
- VERSION = '0.1.0'
2
+ VERSION = '0.1.1'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: replace_with_destroy
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
  - Alexander Leyva
@@ -30,7 +30,8 @@ dependencies:
30
30
  - - ">="
31
31
  - !ruby/object:Gem::Version
32
32
  version: 5.0.7.2
33
- description: Description of ReplaceWithDestroy.
33
+ description: By default automatic deletion of join models is direct, no destroy callbacks
34
+ are triggered. This gem allow changes the default Rails behavior.
34
35
  email:
35
36
  - cyberxander90@gmail.com
36
37
  executables: []
@@ -42,7 +43,7 @@ files:
42
43
  - Rakefile
43
44
  - lib/replace_with_destroy.rb
44
45
  - lib/replace_with_destroy/version.rb
45
- homepage: http://rubygems.org/gems/replace_with_destroy
46
+ homepage: https://github.com/cyberxander90/replace_with_destroy
46
47
  licenses:
47
48
  - MIT
48
49
  metadata: {}
@@ -65,5 +66,5 @@ rubyforge_project:
65
66
  rubygems_version: 2.7.6
66
67
  signing_key:
67
68
  specification_version: 4
68
- summary: Summary of ReplaceWithDestroy.
69
+ summary: Call destroy callback on removed records when Rails update join models
69
70
  test_files: []