vandal 0.0.0 → 0.0.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/.circleci/config.yml +2 -2
- data/README.md +20 -14
- data/lib/vandal/version.rb +1 -1
- data/lib/vandal.rb +38 -1
- data/vandal.gemspec +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fece4c65b959612f8fb5faac683c5e8bbd83d857
|
4
|
+
data.tar.gz: a51419ed4045344409cfe60bae47b7911f538d8c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 23b0d2fa48fc9d920edead140b2f74a14537d50b19c1dea56722925c55f04d38a71acede6b68f975677bc877b3055d38926ba659ba153475007768e1a2d6b9b0
|
7
|
+
data.tar.gz: 101e90b49be4619b669c87a7a0ee52f0bc9d76fd297731beffc7ee633d80822c2571cdaff86e4a1a729b2aff11b4c2b4b5db41e824075c9db508303c80b1377e
|
data/.circleci/config.yml
CHANGED
@@ -9,14 +9,14 @@ jobs:
|
|
9
9
|
|
10
10
|
- restore_cache:
|
11
11
|
keys:
|
12
|
-
-
|
12
|
+
- vandal-bundle-v2-{{ checksum "vandal.gemspec" }}
|
13
13
|
|
14
14
|
- run:
|
15
15
|
name: Bundle Install
|
16
16
|
command: bundle check || bundle install
|
17
17
|
|
18
18
|
- save_cache:
|
19
|
-
key:
|
19
|
+
key: vandal-bundle-v2-{{ checksum "vandal.gemspec" }}
|
20
20
|
paths:
|
21
21
|
- vendor/bundle
|
22
22
|
|
data/README.md
CHANGED
@@ -1,38 +1,44 @@
|
|
1
1
|
# Vandal
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
TODO: Delete this and the text above, and describe your gem
|
3
|
+
A small gem that help to *delete an ActiveRecord instance or collection with associations* (skipping callbacks or validations)
|
6
4
|
|
7
5
|
## Installation
|
8
6
|
|
9
|
-
Add this line to your application's Gemfile
|
7
|
+
Add this line to your application's Gemfile and then execute `bundle install`
|
10
8
|
|
11
9
|
```ruby
|
12
10
|
gem 'vandal'
|
13
11
|
```
|
14
12
|
|
15
|
-
|
13
|
+
## Usage
|
16
14
|
|
17
|
-
|
15
|
+
Vandal gem adds 2 methods to `ActiveRecord::Base`
|
18
16
|
|
19
|
-
|
17
|
+
## #vandal_destroy!
|
20
18
|
|
21
|
-
|
19
|
+
Delete an ActiveRecord instance with associations even if the callbacks return false or rescue error.
|
22
20
|
|
23
|
-
|
21
|
+
```ruby
|
22
|
+
class User
|
23
|
+
has_many :followers # Does not contain dependent: :destroy
|
24
|
+
end
|
24
25
|
|
25
|
-
|
26
|
+
User.find_by(id: 1).vandal_destroy!
|
27
|
+
```
|
28
|
+
|
29
|
+
Followers will deleted along with `User`.
|
26
30
|
|
27
|
-
##
|
31
|
+
## #vandal_destroy_all!
|
28
32
|
|
29
|
-
|
33
|
+
Applies `vandal_destroy!` for ActiveRecord collection
|
30
34
|
|
31
|
-
|
35
|
+
```ruby
|
36
|
+
User.all.vandal_destroy_all!
|
37
|
+
```
|
32
38
|
|
33
39
|
## Contributing
|
34
40
|
|
35
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
41
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/kirillshevch/vandal.
|
36
42
|
|
37
43
|
## License
|
38
44
|
|
data/lib/vandal/version.rb
CHANGED
data/lib/vandal.rb
CHANGED
@@ -1,5 +1,42 @@
|
|
1
1
|
require 'vandal/version'
|
2
|
+
require 'pry-byebug'
|
2
3
|
|
3
4
|
module Vandal
|
4
|
-
|
5
|
+
module Destroy
|
6
|
+
extend ::ActiveSupport::Concern
|
7
|
+
DELETE_OPTIONS = [:destroy, :delete, :delete_all]
|
8
|
+
|
9
|
+
def vandal_destroy
|
10
|
+
begin
|
11
|
+
@destroying ||= false
|
12
|
+
return if @destroying
|
13
|
+
@destroying = true
|
14
|
+
self.class.transaction do
|
15
|
+
self.class.related_associations.each do |association|
|
16
|
+
related = self.send(association[:name])
|
17
|
+
related.send("vandal_destroy#{association[:collection] ? '_all': ''}") if related.present?
|
18
|
+
end
|
19
|
+
self.delete
|
20
|
+
end
|
21
|
+
ensure
|
22
|
+
@destroying = false
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
module ClassMethods
|
27
|
+
def vandal_destroy_all
|
28
|
+
transaction { find_each { |r| r.vandal_destroy! } }
|
29
|
+
end
|
30
|
+
|
31
|
+
def related_associations
|
32
|
+
@related_associations ||= reflections.select do |name, association|
|
33
|
+
association.options[:dependent].in?(DELETE_OPTIONS)
|
34
|
+
end.collect { |name, association| { name: name, collection: association.collection? } }
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
class ActiveRecord::Base
|
41
|
+
include Vandal::Destroy
|
5
42
|
end
|
data/vandal.gemspec
CHANGED
@@ -8,7 +8,7 @@ Gem::Specification.new do |spec|
|
|
8
8
|
spec.authors = ['Kirill Shevchenko']
|
9
9
|
spec.email = ['hello@kirillshevch.com']
|
10
10
|
|
11
|
-
spec.summary = 'ActiveRecord force destroy
|
11
|
+
spec.summary = 'ActiveRecord force destroy records with associations'
|
12
12
|
spec.description = spec.summary
|
13
13
|
spec.homepage = 'https://github.com/kirillshevch/vandal'
|
14
14
|
spec.license = 'MIT'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vandal
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kirill Shevchenko
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-05-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -80,7 +80,7 @@ dependencies:
|
|
80
80
|
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
|
-
description: ActiveRecord force destroy
|
83
|
+
description: ActiveRecord force destroy records with associations
|
84
84
|
email:
|
85
85
|
- hello@kirillshevch.com
|
86
86
|
executables: []
|
@@ -124,5 +124,5 @@ rubyforge_project:
|
|
124
124
|
rubygems_version: 2.6.13
|
125
125
|
signing_key:
|
126
126
|
specification_version: 4
|
127
|
-
summary: ActiveRecord force destroy
|
127
|
+
summary: ActiveRecord force destroy records with associations
|
128
128
|
test_files: []
|